The time now is Tue 18 Jun 2013, 23:47
All times are UTC - 4 |
| Author |
Message |
dave45
Joined: 13 Dec 2010 Posts: 3
|
Posted: 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
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1239 Location: Ukraine
|
Posted: 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
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: 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
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: 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;
}
|
 |
| Description |
|

Download |
| Filename |
mc.png |
| Filesize |
406.29 KB |
| Downloaded |
215 Time(s) |
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: 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";
}
}
|
 |
| Description |
|
| Filesize |
4.18 KB |
| Viewed |
908 Time(s) |

|
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: 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";
}
}
|
 |
| Description |
|
| Filesize |
6.62 KB |
| Viewed |
906 Time(s) |

|
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: 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
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: 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
|
| Description |
|

Download |
| Filename |
mc.pet |
| Filesize |
1.5 KB |
| Downloaded |
165 Time(s) |
|
|
Back to top
|
|
 |
|
|
|
Rules_post_cannot Rules_reply_cannot Rules_edit_cannot Rules_delete_cannot Rules_vote_cannot You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|