Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 20 Oct 2014, 14:29
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Perl on Lucid Puppy
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
dave45

Joined: 13 Dec 2010
Posts: 3

PostPosted: Mon 13 Dec 2010, 13:48    Post subject:  Perl on Lucid Puppy  

I'd like to teach myself perl and have Lucid Puppy running nicely. I've managed to load a version of perl OK but trying to access CPAN modules blows out with "stuff not loaded" errors.

I guess I'm missing something in the configuration or have loaded the wrong version.

Is there an idiot's guide to loading perl on Lucid Puppy some kind person can point me to?

tvm
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Mon 13 Dec 2010, 17:45    Post subject: this is not programming  

Please leave this part of the forum for programmers....perl is part of every puppy that I know of, starting from 1.07 in my experience.
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Mon 13 Dec 2010, 20:27    Post subject: Re: Perl on Lucid Puppy  

dave45 wrote:
I'd like to teach myself perl and have Lucid Puppy running nicely. I've managed to load a version of perl OK but trying to access CPAN modules blows out with "stuff not loaded" errors.

I guess I'm missing something in the configuration or have loaded the wrong version.

Is there an idiot's guide to loading perl on Lucid Puppy some kind person can point me to?

tvm


Perl is already installed in Lucid.

Code:

#!/usr/bin/perl

print "hello world\n";


edit: here's one:
http://www.tizag.com/perlT/perlfirstscript.php
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Tue 14 Dec 2010, 20:39    Post subject:  

Here's a little cli calculator; does cube roots, etc to specified digits.


USEAGE: [num] [sign] [num] [-s decimals ]
operators: +, -, /, %, \* or m, ^

Code:

#!/usr/bin/perl

### mc calculator: jpeps  12/10


$one="$ARGV[0]";
$two="$ARGV[2]";
$sign="$ARGV[1]";
$switch="$ARGV[3]";

if ( $switch  eq "-s"){
 $scale="$ARGV[4]";
}
else {
 $scale="2";
}
## Scale factor
$x = join "", "%.", $scale, "f";


sub help {

print "USAGE: [num] [sign] [num] [-s decimals ]\n";
print "operators: +, -, /, %, \\* or m, ^\n"; 
}

## Math routines

sub add {
print ($one + $two);
print "\n";

}
sub subtract {
print ($one - $two);
print "\n";
}
sub multiply {
print ($one * $two);
print "\n";
}

sub divide {
$number = $one / $two;
printf $x, $number;
print "\n";
}

sub modulus {
print ($one % $two);
print "\n";
}

sub power {
$number = $one ** $two;
printf $x, $number;
print "\n";
}

### Begin Program

if (($one eq "") || ($one eq "-h")){
help;
exit;
}

if ($sign eq "+"){
add;
}
elsif ($sign eq "-"){

subtract;
}
elsif (($sign eq "*") || ($sign eq "m")){

multiply;
}
elsif ($sign eq '/'){
divide;
}
elsif ($sign eq '%'){
modulus;
}
elsif ($sign eq '^'){
power;
}
mc.png
Description 
png

 Download 
Filename  mc.png 
Filesize  406.29 KB 
Downloaded  291 Time(s) 
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Fri 17 Dec 2010, 05:55    Post subject:  

More developed version of MC calculator. This one accepts a chain of numbers to specified digits.


Code:

#!/usr/bin/perl

## CLI calculator 12/10 jpeps

$one="$ARGV[0]";
$two="$ARGV[2]";

## check for -s switch
@switch=grep(/\-s/, "@ARGV");
if ("@switch"){
$var="@switch";
@s = split('\-s', $var);
$scale="$s[1]";

## remove leading whitespace
$scale =~ s/^\s+//;
}
else {
 $scale="2";
}

## Scale factor for number of digits
$x = join "", "%.", $scale, "f";


sub help {

print "USAGE: [num] [sign] [num].. [-s decimals ]\n";
print "operators: +, -, /, %, \\* or m, ^\n"; 

}

## Math routines
sub add {

 $result = $one + $two;
if (( ! "$ARGV[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$ARGV[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}

sub subtract {
 $result = $one - $two;
if (( ! "$ARGV[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$ARGV[$n+1]" eq "\-s") {
}
}

sub multiply {
$result =  $one * $two;
if (( ! "$ARGV[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$ARGV[$n+1]" eq "\-s") {
}
}

sub divide {
$result = $one / $two;
if (( ! "$ARGV[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$ARGV[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}

sub modulus {
$result =  $one % $two;
if (( ! "$ARGV[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$ARGV[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}

sub power {
$result = $one ** $two;
if (( ! "$ARGV[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$ARGV[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}
## End of Subs

### Begin Program

if (($one eq "") || ($one eq "-h")){
help;
exit;
}

## Set args  for $two and $sign
$n = "0";
$i = "0";

## Begin while loop: loops through arguments
while ( "$two" ) {
$i++;
$n = $n + 2;
$two = "$ARGV[$n]";

$sign[$i] = "$ARGV[$n - 1]";


## Begin calculations

if ($sign[$i] eq "+") {
add;
$one = "$result";
}

elsif ($sign[$i] eq "-"){
subtract;
$one = "$result";
}

elsif (($sign[$i] eq "*") || ($sign[$i] eq "m")){
multiply;
$one = "$result";
}

elsif ($sign[$i] eq '/'){
divide;
$one = "$result";
}

elsif ($sign[$i] eq '%'){
modulus;
$one = "$result";
}

elsif ($sign[$i] eq '^'){
power;
$one = "$result";
}
}
mc.png
 Description   
 Filesize   4.18 KB
 Viewed   1010 Time(s)

mc.png

Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Fri 17 Dec 2010, 15:59    Post subject:  

Should be about done. This version eliminates need for whitespaces to make entry easier and more readable. Also, substituted "x" for "m" for multiplication.
Both "x" and "*" required special handling, since they're special characters.

Updated 7/16/11: add negative integers with 'm': 3*m2

Code:

#!/usr/bin/perl

## CLI calculator 12/10 jpeps
## 7/16/11  Add negative integers (m); example: 5*m4

## Add spaces around args
$args="@ARGV";
$args =~ s/\+/ \+ /g;
$args =~ s/\-/ \- /g;
$args =~ s/\*/ x /g;
$args =~ s/\^/ \^ /g;
$args =~ s/x/ x /g;
$args =~ s/\// \/ /g;
$args =~ s/\%/ \% /g;
$args =~ s/\- s/ \-s /;
$args =~ s/m/\-/g;

@args = split(" ",$args);

$one="$args[0]";
$two="$args[2]";
## check for -s switch
@switch=grep(/\-s/, "@args");
if ("@switch"){
$var="@switch";
@s = split('\-s', $var);
$scale="$s[1]";

## remove leading whitespace
$scale =~ s/^\s+//;
}
else {
 $scale="2";
}

## Scale factor for number of digits
$x = join "", "%.", $scale, "f";


sub help {

print "USAGE: [num][sign][num]... [-s decimals ]\n";
print "operators: +, -, /, %, \\* or x, ^\n"; 
print "negative numbers: use m: ex: 5*m4\n";

}

## Math routines
sub add {

 $result = $one + $two;
if (( ! "$args[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$args[$n+1]" eq "\-s") {
printf $x, $result;

print "\n";
}
}

sub subtract {
 $result = $one - $two;
if (( ! "$args[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$args[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";

}
}

sub multiply {
$result =  $one * $two;

if (( ! "$args[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$args[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}

sub divide {
$result = $one / $two;
if (( ! "$args[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$args[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}

sub modulus {
$result =  $one % $two;
if (( ! "$args[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$args[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}

sub power {
$result = $one ** $two;
if (( ! "$args[$n+2]" ) && ( ! "$switch")) {
printf $x, $result;
print "\n";
}
 elsif ( "$args[$n+1]" eq "\-s") {
printf $x, $result;
print "\n";
}
}
## End of Subs

### Begin Program

if (($one eq "") || ($one eq "-h")){
help;
exit;
}

## Set args  for $two and $sign
$n = "0";
$i = "0";

## Begin while loop: loops through arguments
while ( "$two" ) {
$i++;
$n = $n + 2;
$two = "$args[$n]";

$sign[$i] = "$args[$n - 1]";


## Begin calculations

if ($sign[$i] eq "+") {
add;
$one = "$result";
}

elsif ($sign[$i] eq "-"){
subtract;
$one = "$result";
}

elsif (($sign[$i] eq "*") || ($sign[$i] eq "x")){
multiply;
$one = "$result";
}

elsif ($sign[$i] eq '/'){
divide;
$one = "$result";
}

elsif ($sign[$i] eq '%'){
modulus;
$one = "$result";
}

elsif ($sign[$i] eq '^'){
power;
$one = "$result";
}
}
mc.png
 Description   
 Filesize   6.62 KB
 Viewed   991 Time(s)

mc.png

Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Sun 17 Jul 2011, 02:24    Post subject:  

I'm using this calculator quite a bit in scripts, and updated it to include capacity for negative integers using "m"
Code:
 
/mnt/sda2/Desktop $ mc 6*m2
-12.00
/mnt/sda2/Desktop $
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Tue 19 Jul 2011, 13:02    Post subject:  

This bash frontend adds a memory function to the mc calculator, so that typing "M" substitutes in the last result:



change log:
ver. 3.0 7/18/11 added frontend
ver. 3.2 7/19/11 improved memory function; prints with "mc M"
Clear memory with "mc c"

example:
Code:

/mnt/sda2/Desktop $ mc 23.23*2^2 -s3
2158.532
/mnt/sda2/Desktop $ mc M/12
179.88
/mnt/sda2/Desktop $ mc M   
179.88
/mnt/sda2/Desktop $ mc c
/mnt/sda2/Desktop $



script:
Code:

#!/bin/sh
if [ "$1" == "" -o "$1" == "-h" ]; then 
  echo "Substitute "M" for memory; clear with 'mc c'"
   mc
   exit
fi 

VAR=`echo "$@" | grep "M"`

 ## Print memory with "M" option.
 if [ "$VAR" ]; then 
   if [ "$VAR" == "M" ]; then
          cat /tmp/.mc
          exit
   fi 
   if [ ! -f /tmp/.mc -o "$(cat /tmp/.mc)" == "" ]; then
          echo "nothing in memory"
          exit
     fi
    MEM="$(cat /tmp/.mc | sed 's/\-/m/')"
    ARG=`echo "$@" | sed "s/M/$MEM/"`
    mc "$ARG" >/tmp/.mc
 else
   mc "$@" >/tmp/.mc
 
 fi

cat /tmp/.mc
mc.pet
Description 
pet

 Download 
Filename  mc.pet 
Filesize  1.5 KB 
Downloaded  262 Time(s) 
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0860s ][ Queries: 13 (0.0038s) ][ GZIP on ]