Re: how do modules work?

2004-02-17 Thread WilliamGunther
That would be true in some languages. Not in Perl. Modules only "exist" in 
the lexical scope (usually a block, in this case a file/package). So, there's no 
danger in polluting namespace from that module for sure. But, as with 
everything else in Perl, you can access it if you go out of your way. 

So, if you use Data::Dumper in the Foo::Bar class, and you call the Foo::Bar 
class (via use Foo::Bar), you'd have to do &Foo::Bar::Dumper to use it. If you 
understand. Which you probably don't. So wait until someone else answers. :-)

Will

In a message dated 2/17/2004 7:21:35 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
I've been using Perl for about a year. I'm writing my own module that 
contains some custom 
functions that I use a lot. In doing this, I started wondering how modules 
work. For 
example, if my module has 'use SomeModule;' and a script I write has 'use 
MyModule;', does 
that mean that I am effectively saying 'use SomeModule;' in my script?


Re: Why does this keep happening?

2004-02-17 Thread WilliamGunther
#!/usr/bin/perl 
use strict;
use warnings;

my $abc = 1000;

until ($abc == 0) {
print "Counting down to 0 from $abc\n";
--$abc;
};

print "Blast off!\n";


Remember your semicolons and try to use strict. I try to be readable above 
all else. Because then at least if the code doesn't work, it looks really 
pretty. Which is an ongoing theme with me by the way. Pretty Code with little 
function. Heck, in a language with dollar signs all over it and no indent function 
that's a pretty heavy feat.

Will
###
In a message dated 2/17/2004 5:29:50 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
#!usr/bin/perl

$abc=1000

until ($abc==0)
{
print "Counting down to 0 from $a\n";
$a--;
}
print "Blast off!";


Re: how do modules work?

2004-02-17 Thread WilliamGunther
You are in fact using the DBI module. The DB handle is probably (I think it 
is) a bless reference that will send you straight to the DBI module that's 
called in the function you've created. Although you're not using the DBI module in 
your code, you're indirectly using it without ever knowing it if you made a 
good enough class. 

I think. I hope. Maybe I'm completely wrong. I don't know. Someone will 
correct me though. Right or Wrong.

Will


Re: how do modules work?

2004-02-17 Thread WilliamGunther
In a message dated 2/17/2004 8:56:07 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
and then in step 3 
black magic happens and..." to your answer.
We all know step 3 of any Perl code is black magic. Step 4 is optimization. 

Will


Re: Why does this keep happening? (U)

2004-02-18 Thread WilliamGunther
In a message dated 2/18/2004 9:48:24 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
IIRC, I believe Apache uses the shebang line in Perl scripts on the Windows
platform.
You are correct. It does.

Will


Re: Can anyone reccomend a good online perl tutorial

2004-02-18 Thread WilliamGunther
Let me just say, you can learn Perl just from the Perl Documentation. There 
is a LOT of that. It's advaliable online in HTML form at perl.com and cpan.com. 
It's also shipped with perl via perldoc.

http://www.steve.gb.com/perl/ -- This is the best Perl Tutorial I have seen 
online. It goes from beginning to end on any platform.

Will


Re: Problem with LWP::UserAgent

2004-02-18 Thread WilliamGunther
Actually, this is a little bit of an incorrect question. If your first code 
worked (which it doesn't for me by the way), and if in your second 
$config->{URL_1} does equal http://rajeshd, they're the same. So, the problem is 
somewhere 
else.


Re: switch statement

2004-02-19 Thread WilliamGunther
The Advantage is you get to use the switch statement. The disadvantage is 
your code will run extraordinarily slow because the Switch module uses a run time 
Filter. In short: isn't an is-elsif-else statement enough??

In a message dated 2/19/2004 4:40:56 PM Eastern Standard Time, [EMAIL PROTECTED] 
writes:
I don't know the advantages/disadvantages of using it.



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: switch statement

2004-02-19 Thread WilliamGunther

This: 
if ($op == 0) {}
elsif ($op == 1) {}
elsif ($op == 2) {}
elsif ($op == 3) {}
elsif ($op == 4) {}
elsif ($op == 5) {}

is faster than this:

use Switch;
switch ($op) {
case 0 { last }
case 1 { last }
case 2 { last }
case 3 { last }
case 4 { last }
case 5 { last }
}

By a noticably amount. 


In a message dated 2/19/2004 5:47:47 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
Switch allows coding that runs no more slowly than 'if'



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: switch statement

2004-02-19 Thread WilliamGunther
I just benchmarked Filter, and it was worse than 100 times slower


In a message dated 2/19/2004 6:53:56 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
last time i benchmark a source filter, it's about 100 times slower. has that 
change since v5.8?



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: $self

2004-02-19 Thread WilliamGunther
No. $self you'll usually see in a lot of Object Oriented applications. When a 
subroutine is called using the -> operator ($mw = MainWindow->new, for 
example) the first arguement passed to that subroutine is the name of the 
package/class. So, $self is usually used to display this. So, a common constructor is

sub new {
my ($self, %args) = @_;
return bless \%args, $self;
}

Look into perldoc perlboot, perldoc perltoot, perldoc -f bless, etc. Like the 
name "new" for a constructor, you can name it anything you want, but many 
choose to name it $self, because in a constructor it is literally the name of 
your own package, and otherwhere it is a hash blessed to your own package. Hope 
that helps.


In a message dated 2/19/2004 11:24:11 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
is $self a special scalar?



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: lc

2004-02-20 Thread WilliamGunther
lc() takes a string, turns the string to lower case, and returns that. So 
what you're searching for is:

chomp($input = lc());

This way, lc() function turns the input into lowercase, assigns it to the 
$input scalar, and then chomps out the newline at the end. Quite efficent.


In a message dated 2/20/2004 5:22:39 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
The way it is described makes me think that I am using
it correctly, but Perl is telling me different.
So, am I using it incorrectly?  Thanks



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: Shebang line

2004-02-20 Thread WilliamGunther
Yep, in general Unix-style shebang line is fine on Windows. Perl doesn't 
ignore shebang, the switches are still looked at. 

Apache uses the shebang on Windows. 



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: question plz

2004-02-20 Thread WilliamGunther
They're different operators. => is the same thing as the comma. It's sole 
difference is readability.  For example

%hash = ( key => "value",
key2 => "value2",
   );
#is the same as
%hash = ( key, "value",
key2,"value2",
   );
#is the same as
%hash = ( key, "value" =>
key2,"value2" => 
   );
#Although that last one is confusing...

-> is an operator useful when dealing with reference. Not to get into too 
much detail, because it sounds like you're pretty new at Perl from your 
questions, if
$hash_ref = {key => "value", key2 => "value2"};
print $hash_ref->{key};

It will go and get the 'key' key from the hash that $hash_ref points to. This 
works for array, packages, and other stuff too. For example, Foo::Bar->new 
means to go into Foo::Bar module and do the new subroutine. 


In a message dated 2/20/2004 9:54:32 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
what is the difference between

->

and

=>



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: Newbie that needs some help

2004-02-21 Thread WilliamGunther
I would probably write it like this (Although, I'm not sure what that :58 is 
about): 

open(FILE, "file1.txt") or die "Can not open file. ", $!, "\n";
@lines = grep { /:58/ } ;

So you can understand and learn, let me just tell you you're mistakes.

open(FILE, "file1.txt") or die "Can not open file.  $! \n"; #or bounds 
looser. Get in the habbit for using this instead, because if you said "open FILE, 
"file1.txt" || die "Cannot open file. $!\n";" it wouldn't do what you expected.
while ($line = ) {
if ($line =~ /:58/) { #I don't understand why, but I'm assuming this is 
what you want
#You didn't need another loop here
  push (@line, $line); #by saying @lines = $lines, you're changing the 
entire array. Just push $lines to the end.
}
}


In a message dated 2/22/2004 12:05:29 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
open(FILE, "file1.txt") || die "Can not open file.  $! \n";
while ($line = ) {
if ($line =~ /:58/) {
  #print $line; ## For Debugging Only
foreach ($line) {
@lines = $line;
}
}
}
print "@lines";



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: sleep under windows cmd

2004-02-22 Thread WilliamGunther
$| = 1; #Autoflush
print "First";
sleep 2;
print "Second";


-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: \r -Option

2004-02-23 Thread WilliamGunther
That doesn't work because \b will bring the "cursor" back, and not delete 
characters. So what you want is

$| = 1; #Autoflush
my $text = "Test";
print $text;
sleep 2;
print "\b \b" x length($text);
print "OK";

In a message dated 2/23/2004 11:44:35 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
$| = 1; #Autoflush

my $text = "Test";
print $text;
sleep 2;
print "\b" x length($text);
print "OK";



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: how to remove an element in an array

2004-02-26 Thread WilliamGunther
In a message dated 2/26/2004 6:04:59 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>Is there a command to drop an element from an array, or what is the best
>way to do this.
>
>Any help appreciated.

Look into splice. delete doesn't remove elements as you may expect, 
just...deletes them. 
splice ARRAY; OFFSET LENGTH REPLACE

I always just use this, because I hate removing elements and worrying about 
it:

use strict;
use warnings;
sub remove_el (\@@) {
my $array = shift;
my @el_rem;
for (sort {$b <=> $a} @_) {
if (! exists $array->[$_]) {
warn 'element ', $_, ' does not exist';
next;
}
push @el_rem, splice(@$array, $_, 1);
}
return @el_rem;
};

my @sample = ('a', 'b', 'c', 'd', 'e', 'f', 'g');
remove_el @sample, 6, 2, 4, 1;

If you just need to remove 1 element a time or a length of elements, you 
should just use splice. But sometimes when you have to remove different elements 
in no particular order at no particular time, it gets annoying. Especially if 
you are doing something and you have to remove element 3 and 8 at the same 
time, and if you remove 3 first, element 8 will be different. We have subroutines 
to make considering this stuff more than once minimal. 


-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Installation

2004-02-26 Thread WilliamGunther
In a message dated 2/26/2004 10:06:57 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
have downloaded 5.8 from ActiveState.  Before I install it are they any 
"Gotchas" or glitches that I should know about?
Are you on a Windows system?



-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: subroutine definitions

2004-02-28 Thread WilliamGunther
In a message dated 2/28/2004 3:28:55 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
 > - Stop using prototypes. You'll find it easier to write perl
 >   programs without them.

Prototypes are useful and sometimes necessary, as in the supplied problem. 
What would be called 

my_subroutine($scalar1, $scalar2, [EMAIL PROTECTED], [EMAIL PROTECTED]);

, is now called 

my_subroutine $scalar1, $scalar2, @array1, @array2;

This may be perfect for the problem at hand. Also, for constent values, 
prototypes ARE 100% neccisary (That's why if you do h2ph on #define PI 3.14 the 
returned subroutine has a null prototype). Also, for code reference, prototypes 
are a good, easy way to handle it (As with glob prototypes and File Handles). 

Prototypes exist for a reason. Should you use them in every case? No, but 
they have reasons to exist, and you should use them when you think it's one of 
those reasons. The real problem with prototypes is they may be overused, and 
they may be misused/misunderstood (sub my_subroutine ($scalar, @array, @array) {) 

-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Automatically write in uppercase

2004-02-29 Thread WilliamGunther
In a message dated 2/29/2004 7:31:49 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>That's a nice method but i would prefer to activate the CAPS-LOCK and user
>write in capitals in my text entry widget

 
I can't think of how (or why) you'd want to do that. If you want them to type 
in caps, just turn the data to upper case when you need it. 

If you really really want to do that then you probably have to do a binding 
on any keypress in the text widget to change everything to upper case. That's 
the only way I can think to do it, but I'm not super up on my Tk. My method is 
slow, especially for a lot of stuff, and unnecessary since you can change it 
all to upper case after they say they're done.


-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: Ternary operator question

2004-03-02 Thread WilliamGunther
In a message dated 3/2/2004 9:21:57 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>$#array + 1 still is the size of the array and it won't modify the 
>array.  That's not what we were talking about.  We were talking about 
>++$#array, which expands to $#array = $#array + 1.  Note the equal sign 
>there, because it's what modifies the array.

$#array + 1 is the length99% of the time. Until you modify $[, in which case 
the size is $#array - $[ + 1. But, don't modify $[ (unless you want to :-) )

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: OO Programming

2004-03-02 Thread WilliamGunther
In a message dated 3/2/2004 7:57:45 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>Is there any good documentation for in OO PERL Programming?

Yep. In no particular order:

 perldoc perlref
 perldoc perlboot
 perldoc perltoot
 perldoc perltooc
 perldoc perlbot
 perldoc perlobj
 perldoc perlreftut

IMHO, Object Oriented Perl is the best book you can get on the subject.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: Passing array as First argument

2004-03-03 Thread WilliamGunther
In a message dated 3/3/2004 5:15:57 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>testsub(@abc, $x, $y);
>
>sub testsub(@$$)
>{
>(@abc, $x, $y) = @_;
>print "Array @abc\n";
>print "x $x\n";
>print "y $y\n";
>}

sub testsub ([EMAIL PROTECTED]);
@abc = (1, 2, 3);
$x = 3;
$y = 4;
testsub @abc, $x, $y; #parens now optional

sub testsub([EMAIL PROTECTED])
{
my ($abc, $x, $y) = @_; # @abc is reference to array @abc
print "Array", @$abc, "\n";
print "x ", $x, "\n";
print "y ", $y, "\n";
}


-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: hi!!

2004-03-05 Thread WilliamGunther
>In a message dated 3/5/2004 6:11:53 PM Eastern Standard Time, 
>[EMAIL PROTECTED] writes:
>i have downloaded cygwin and perl 5.0 comes along with it.
>How can i access perl from cygwin. My purpose is only to be able to write a 
script in perl >and run it using cygwin. Can anyone help me with this..
>
>regards
>aalok

 
To be specific, I think perl 5.8.2 comes with cygwin :-) You access perl 
through cygwin like normal. Just run cygwin and run, 'perl /path/to/script.pl'. 
Or, if you put the path (#/usr/local/bin/perl on cygwin) you can run it as 
"/path/to/script.pl" (Remember though, if you're in the directory of the perl 
script, it isn't "script.pl" it is "./script.pl")

If you have already been coding Perl on a Windows system (just assumed your 
on a Windows system because you got cygwin) it doesn't take too much getting 
use to since you've had to learn Perl for Unix and then figure out to exceptions 
for Windows. cygwin is a relief after you've been fumbling with mc and 
ActiveState. 


-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: Passing array as First argument

2004-03-07 Thread WilliamGunther
In a message dated 3/7/2004 6:58:57 AM Eastern Standard Time, [EMAIL PROTECTED] 
writes:
>This is quite a common and simple problem for which reading the whole 
>perldoc perlsub might be somewhat too confusing, but asking about it on 
>mailing lists usually starts discussions which often become arguments on 
>whose favorite style is better, so I'll do my best to describe every 
>possible way as objectively as I can, and then I'll say which style I 
>would personally use in which circumstances.

Very nice. Thank you for posting it. You do bring up a very good point that 
references may not be what you want. References have a lot of significance and 
value, and sometimes they don't do what you want them to do. If, for (a very 
simplistic) example 

my $a = 2;
chref(\$a);

sub chref {
my $ref = shift;
$$ref = 3;
}

will modify the value of $a, which may not be what you want. And saving the 
value of complex data structures isn't the most enjoyable thing in the world. 
(I'd compare it to for chemistry making your own test tubes for every single 
experiment. Thank God for the Clone module however.) So, my only advice to the 
OP is if you're going to use references, know how to use them, and what they 
do. In the problem you presented, they're not entirely necessary (unless you 
WANT to modify the array's value). 

Your discussion was very well written and informative. Thanks again.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Variable matching.....

2004-03-09 Thread WilliamGunther
In a message dated 3/9/2004 2:43:16 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>Hi all, I'm trying to figure out how can I check if a variable matches the 
>first 5 digits of the line below without removing anything from the line. 
>
>13384 R 20020920 N Gatekeeper, The
>
>Silver Fox

use strict;
use warnings;
my $line = "13384 R 20020920 N Gatekeeper, The";
my $var = 13384;
my ($match) = ($line =~ /(\d{5})/);
print "Match! ", $var,"==", $match,"\n" if $var == $match;
#OR
my $substr = substr $line, 0, 5;
print "Match! ",$var,"==",$substr,"\n" if $var == $substr;

#Is the line the same?
print $line,"\n";



-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Variable matching.....

2004-03-09 Thread WilliamGunther
In a message dated 3/9/2004 3:08:10 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>Careful, I believe we want the above capture anchored to the start of
>the line, though I prefer the direct match approach...

You're right about the anchor, but direct match wouldn't be the preferable 
method here. Say, using your code, my $variable = 1338. The regex is true, even 
though the number will be different.You'd have to do /^$variable\s+/ (even 
then, $variable could be "13384 R", be true, and mess things up). Regex in 
conditionals can be effy and ambiguous, and if they can be avoided, why not avoid 
them. 

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: String differences

2004-03-25 Thread WilliamGunther
In a message dated 3/25/2004 6:02:03 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>Any differences between strings quoted with ' vs "?
>I know the '' delimited strings don't get variables and other nice
>things converted to values, does that make '' faster when using constant
>strings than ""?

' and " are different. The Single quote is faster, to answer your question. 
Double quotes are interpolated. In simple terms, perl will break apart (or try 
to) double quote string to single quote string, hence its slowness. So 
something like:

print "You picked $number";

will be changed to

print 'You picked ' . $number;

(In this case, the fastest solution would be print 'You picked ', $number;)

All this kind of stuff is gone over in Master Perl Algorithms, which is a 
good read.


-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: why warn 'prints'?

2004-03-26 Thread WilliamGunther
warn is a debugging function that prints a message to the STDERR (Not print, 
which can print to anything and prints to STDOUT by default) and appends your 
message with a line number and such. It's just like die, that doesn't exit. 
Another difference is print uses $_ by default, and warn uses $@ by default.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: using strict

2004-04-01 Thread WilliamGunther

In a message dated 4/1/2004 5:03:40 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
People of the Perl, 

>from my understanding strict disallows soft references, ensures that all 
>variables are declared before usage and disallows barewords except for 
>subroutines.
>
>what is a soft reference?

A soft reference is a symbolic reference. For example:
$hello = "Hey, what's up?";
$var = "hello";
print $$var; #or, if it helps you see it better 'print ${$var}'

This may be what you want, but may not be (usually you want hard references), 
hence use strict 'refs'

>what is a bareword?

A bareword is...a bare...word? Really its just a word not expicitly denoted 
to be something. For example:

sub foo { 1 }

foo;

foo is a barewords. In the above case, strict doesn't freak out because the 
subroutine is predeclared. But if you just throw around words whenever you 
want, it will freak out. For example,
@array = (String, String, String, String);

String is a bareword. strict will throw up an exception so fast. 

2 exceptions to the bareword throw-up: left side of '=>' and inside curly 
braces. For Example: 

%hash = (
left => 'right'
)
print $hash{left};




>why is strict disallowing a compile here When I comment out strict the 
>syntax checks outs as ok!???
>how do I display each element # with its corresponding data line, b/c I 
>only want certain elements printed out?

People already answered these. On an aside, Your code may compile dandy, 
that's not what strict is for. If perl could catch the errors like the ones you 
stated, there would be no need for strict. Strict is basically just so you don't 
screw up. You don't want barewords because you might think it means something 
else. You don't want soft references when you think you're using hard 
references. You don't want your code to screw up and you not to know why cause you 
used $var on 10,000 of the 20,000 lines and $Var on the other 10,000.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: Timezone conversion

2004-04-02 Thread WilliamGunther
In a message dated 4/2/2004 3:20:12 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>can someone give me ideas of how I could covert this date and time stamp
>that is in GMT to Central time ?
>
>2004-04-01-19:15:15.525+00:00

In the above case, it would be fine to just subtract the hour offset between 
GMT and CST. But, that really isn't a complete solution as if it is say 1 AM 
GMT, it is a different day CST. Your best bet is to either make it yourself 
(IMHO, reinventing the wheel can be quite enjoyable, and almost definetly more 
suitable for your needs. Plus in Perl this could be really fun to make your own 
date objects and overdriving some stuff.) or to use a cool module 
(Date::Object is what I'd use). 


-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Subroutine and @_ confusion

2004-04-05 Thread WilliamGunther
In a message dated 4/5/2004 7:52:33 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Hi People
>
>I'm trying to get a grip on passing @_ to subroutines. Or rather NOT
>passing it.
>
>I have a package:
>
>sub HLOM::Links::new {
>my ($class, %arg) = @_;
>my $userid = 0;
>if ($arg{userid}) {$userid = int $arg{userid};}
>bless {
>_UserID => $userid,
>_LinkID => 0,
>_longmessage => "",
>_shortmessage => "",
>_error => ""
>}, $class;
>}
>
>and several subroutines.
>
>These subroutines are called externally ie HLOM::Links->FindLink(LinkID
>=> $id);
>
>but also internally ie  &FindLink(LinkID => $id);



FindLink is excepting the class as the first arguement, which it doesn't get 
here. This is going to do things that are really going to get messed up. 
LinkID is going to be taken as the class, and the rest is a hash, but it's an odd 
number of elements are you alluded to, so it's not going to look good, or 
really do any good for anyone.



>
>I read in Perlsub that doing &FindLink will pass the current @_ to the
>subroutine. Great.
>
>But I thought that doing &FindLink(LinkID => $id); would not pass the
>current @_ which is what I want. ie I only want to pass the param
>LinkID not all the other stuff that was passed to the subroutine that
>called the subroutine
>
>here's a sample of the subroutine. Really simplified as it's quite long.
>
>sub AddLink {
>my ($class, %arg) = @_;
>my $userid = $_[0]->{_UserID};
>my $LinkUrl = $arg{LinkUrl};
>my $LinkTitle = $arg{LinkTitle};
>my $newlinkid = 0;
>my $fc = 0;
># a load of stuff snipped.
># adds link and sets $newlinkid to the id of link
>if ($newlinkid > 0) {$fc = &FindLink(LinkID => $LinkID);}
>if ($fc > 0) {
>$_[0]->{_error} = "";
>$_[0]->{_shortmessage} = "Link added\n";
>}
>return $newlinkid;
>}




I'm not sure if the above connotes what it does. Usually you do not use 
$class for a variable if it is a reference, you would use it for a class name 
usually in a constructor. Try this line instead of its counterpart; not knowing 
more this is all I can suggest at this point.

 if ($newlinkid > 0) {$fc = $class->FindLink(LinkID => $LinkID);}




>what's happening is the current @_ is being passed to the subroutine
>FindLink even though I'm adding arguments. All my subroutines have "my
>($class, %arg) = @_ ;" at the start of them. but the error log says the
>following:
>
>Odd number of elements in hash assignment
>
>looking through the hash the error is right. It's like the hash has
>become mangled. It appears as if the first element of the array (Ie the
>hash key LinkID) has been stripped.
>
>here's the output when traversing the hash:
>
>3123 =>
>LinkNotes =>
>LinkTitle => perlsub
>LinkID => 3123
>LinkUrl => http://www.perldoc.com/perl5.6.1/pod/perlsub.html
>
>The first line should be LinkID => 3123
>
>And the rest of it should NOT be being passed. I just don't get it.
>
>I thought that maybe I need to pass $class explicitly when doing this.
>That fixed it in the past, but then I thought maybe I should ask
>someone who actually knows. I do want to pass the class and  the args
>explicitly added but not the %arg that was in the calling subroutine.
>
>Anyone?
>
>TIA
>
>Angie
>


-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: Subroutine and @_ confusion

2004-04-05 Thread WilliamGunther
In a message dated 4/5/2004 11:25:56 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>I have seen shift used in Subroutines like: "NumberOfApples = 
>shift(@_);",
>any reason for writing the subroutine that way?

You'll frequently see shift in subs. Like "$class = shift;" (Default for 
shift is @_, so you don't need to explicitly say it, and few do) I personally like 
to just say "($class, %args) = @_" because then you still have @_ intact, 
which is crazy useful at times. Why write it this way? Brevity. Since @_ is 
modified you can say "$class = shift; %args = @_;" and that works. "$class = $_[0]; 
%args = @_;" will probably be an error.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl/TK

2004-04-07 Thread WilliamGunther
>Hello,
>
>I am taking a look at some Ptk codes, and I think I need a to do some
>reading.  So my question is:
>
>1./ What is a good source or reference materials/books on Perl/Tk?

Two books. Learning Perl/Tk and Mastering Perl/Tk. I think Mastering Perl/Tk 
is really all you need. There's also a pocket reference that I have and it is 
quite helpful because Tk is a pretty extensive module. But, really, like Perl, 
you don't need to buy books to learn. There is a lot of docmentation just 
with pods. A LOT. And because Perl/Tk is so extensive and dynamic, you won't 
learn all you can if you never looked at them. Navigate the pods (For something 
like Tk, you would be best with perldoc.com) and check out the FAQs 
(http://www.lns.cornell.edu/~pvhp/ptk/ptkFAQ.html) and go from there.

>2./  Can anyone recommend a class that will help lower my learning curve
>(specifically on Perl/Tk).  As far as Perl goes, I can say I feel decently
>comfortable detecting codes written in Perl.  Perl/Tk, however, is a
>different ball game.

Honestly, if you just get Learning Perl/Tk it's very simple to pick up. 
Sometimes its easy to get lost when you start Perl/Tk because its looked at as 
something other than what it is: a Perl Module. You shouldn't have too much 
trouble if you have command of perl in making GUIs. I wouldn't take a class just for 
the Tk module. 

>
>Thank you.
>
>


-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: AW: book suggestion for atypical beginner

2004-04-08 Thread WilliamGunther
In a message dated 4/8/2004 7:49:04 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Holger> Holger Schell
>
>Randal> Sir, how do you sleep at night?   You personally offend me now.
>Randal> You've just taken money DIRECTLY out of my pocket.

You deserve the money too. You've helped a lot of people, including myself 
learn. And you posting in this list is a testament to your generosity.

>
>In fact, let me take this one step further.  I've been told recently
>(although I might be misremembering) that O'Reilly will publish NO
>MORE CDs because of rampant piracy.
>
>How does it feel to be a cog in the wheel of the end of an era?
>
>So, no more nice CDs.  Just dead trees.  Lots of em.

Pirating books is even more stupid considering almost all of the basic books 
you need you can probably find at the library. 

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Solve equations ...

2004-04-09 Thread WilliamGunther
In a message dated 4/9/2004 12:47:13 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Hi,
>
>I would like to solve a system of equations for
>example a system 6x6 with perl. But I really don't
>know how to do it. First is it possible and then if
>yes how?
>
>Thank you,
>
>Romain

I wrote a module for that: Math::Systems. It's slow and bad, and really, just 
a front end to Cramer's law (which you might want to look into) :-) Also, 
this, among other mathematical topics, is discussed in "Mastering Algorithms with 
Perl"

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: guessing script

2004-04-15 Thread WilliamGunther
In a message dated 4/15/2004 12:09:40 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
Learning Perl here..  So I wrote this number guessing script but can't see 
what is wrong with it.  I can never get the solution even when I know it's 
correct.  What am I doing wrong?
[Snipped Code]

It has to do with the scope of guess. You used my twice. Get rid of that my 
in "chomp(my $guess = );  " and then it's good. The $guess being 
evaluated in the while() condition is undef because that is what it has been defined 
to be in that scope. By saying "chomp(my $guess = );" you're saying 
that this is kind of a new $guess specific to that block, and it doesn't even 
exist outside of it.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: why $a became 6 ?

2004-04-15 Thread WilliamGunther
In a message dated 4/15/2004 2:25:14 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>$a=100; $b=200;
>($a=3 && $b=6 ) if ( 1 == 1 );
>print " $a   $b  \n";
>
>Output : 6   6  
>
>OR my syntax is wrong ? 

&& binds pretty tight. If it helps to see the parenthesis here is what you 
said:
 ($a = ($b = 6));

What you want is:
$a=3 and $b = 6

Or override it with parens yourself
($a=3) && ($b=6) 


PS. Don't use $a and $b

>regards,
>Jay

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Re: Flag for script

2004-04-15 Thread WilliamGunther
In a message dated 4/15/2004 3:19:04 PM Eastern Daylight Time, [EMAIL PROTECTED] 
writes:
>I'm trying to create a script with where you can put a flag to the script or
>not
>fx run it like:
[Rest snipped]

It's best not to deal with @ARGV directly if you want to do the fancy stuff. 
Look into Getopt::Std or Getopt::Long.

perldoc Getopt::Long 
perldoc Getopt::Std

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Simple regex

2004-04-15 Thread WilliamGunther
In a message dated 4/15/2004 7:13:09 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>How can I write a regular expression to keep the part of a string that's
>between a pair of square braces?  Here's a sample line:
>
>Updating Wellbore Set Keys: [wlbr_id = 1234567890, data_provider_code =
>MTBL, welltype = OIL]

How does this sound?

my $string = q(Updating Wellbore Set Keys: [wlbr_id = 1234567890, 
data_provider_code = MTBL, welltype = OIL]);
my @matches = $string =~ m/\[(.*?)\]/g;
local $, = "\n";
print @matches;

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier
-DBD::SQLite

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: what the? Code not working on Windoze

2004-04-17 Thread WilliamGunther
In a message dated 4/17/2004 10:29:01 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Any preliminary thoughts? I have code that works perfectly on my linux
>machine. I'm trying to migrate it to the Windows server these people have
>and now it runs badly. 

Helps to show some code :-)

>My CGI::FormBuilder forms don't render well and I
>keep finding 'Useless use of a constant in Void context" errors in the log
>file, but these ran fine on UNIX. Is there a general rule of thumb for
>figuring this stuff out? (Yes I have installed the correct modules on the
>windows box, via ppm.)
>Thanks,
>John

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier
-DBD::SQLite

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: What exactly is this simple regex doing?

2004-04-17 Thread WilliamGunther
In a message dated 4/17/2004 10:33:51 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>why was ^[^\.]+ suggested rather than ^.*?\. as a pattern.

I just Benchmarked it. qr(^.*?\.) is faster. 

#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw/cmpthese/;
cmpthese(0, {
'^[^\.]+' => sub {
my $var = 'http://www.yahoo.com';
$var =~ s/^[^\.]+//;
 },
'^.*?\.' => sub {
my $var = 'http://www.yahoo.com';
$var =~ s/^.*?\.//;
},
}
);

Results:
Rate ^[^\.]+  ^.*?\.
^[^\.]+ 665905/s  ---25%
^.*?\.  891879/s 34%  --

I think ^[^\.]+ looks better. But that's just me :-)

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier
-DBD::SQLite

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: starting perl

2004-05-02 Thread WilliamGunther
In a message dated 5/2/2004 9:08:37 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>I am a beginner here with learning perl. I have downloaded a perl program 
that also came 
>with apache and the installer to install t hem. But when I try and run the 
hello world 
>program in dos it dose not work. I am getting an error that it could not be 
found.
>
>anyone have any idea what I could have done wrong? 
>

Tell us what you're running in dos exactly. Copy and Paste the whole dang 
thing.
-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: starting perl

2004-05-02 Thread WilliamGunther
>Hi William and all,

Hi


>
>> Most Useful Perl Modules
>> -strict
>> -warnings
>why is it everyone keeps suggesting use warnings when you could use
>diagnostics and get a whole lot of more info?
>I'd go for the diagnostics instead of the warnings module. Does this
>have any negative side effects (besides working towards the title of
>most-annoying-know-it-all) or why exactly is everyone advising warnings
>over diagnostics?

Just some background on my list...Those modules listed on my signature are 
for the benefit of people new to Perl that are curious about what modules to 
look at. There's not the only ones I suggest using, but I think they are in fact 
so useful to development and some common situations that I put them on my 
signature, and continue to add to it whenever I find something cool (added 
DBD::SQLite a couple weeks ago because it is AWESOME. Use it if you don't already)

That being said, I will never put diagnostics on my list. I hate diagnostics. 
I think it's longwinded, and it's generally general statements about problems 
are ignorant. It always fogs up my output. Look at the output of "use 
diagnostics; print $i;". If anyone likes diagnostics, sorry. TMTOWTDI. I like 
warnings and it's usually one line SUGGESTIONS. My code always begins "use strict; 
use warnings;" and I ain't changing it.

>
>Stephan
>
>
>

-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 


Re: Extracting number from string

2004-05-03 Thread WilliamGunther
In a message dated 5/3/2004 2:58:40 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Hello All,
>
>I need a regular expression to extract only the number from the below 
>string.  How is this done?
>
>x=G1234v00
>
>Result=1234
>
>William Black

print 'G1234v00' =~ /(\d+)/;

-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: inline editing of files, searching for \n\n\n

2004-05-10 Thread WilliamGunther
In a message dated 5/10/2004 12:22:06 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Hi,
>
>I have got two versions of a script to eliminate single line-feeds from
>a file.  The first one does weird stuff - duplicating lines and messing
>the text file up.  The second one works (I copied it from a Perl guide),
>but I don't understand why.  I would much prefer the first one to work -
>Can you tell me how to change the first one to make it work?
>
>Also, I understand that the <> operator reads in one line at a time.  If
>I wish to eliminate only triple line-feeds (\n\n\n) and leave double and
>single linefeeds, I presume <> won't work.  Without reading in the whole
>file at once, how can I achieve this?
>
>[codes snipped]
>

Working off your sample code, how about:

$filetobechanged = "iBook HD:Desktop Folder:tim.txt";
@ARGV = ($filetobechanged);
$^I = ".bak";
$/ = "\n\n\n";
while (<>) {
 s/\n\n\n/;
 print;
}

-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Problem with use strict;

2004-05-14 Thread WilliamGunther
In a message dated 5/14/2004 3:05:01 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Hi there.
>Brand new to PERL so please bear with me.   (I'm running Win32/Apache)
>
>When I include the line 
>use strict;
>in any perl program, I get the following error:
>"Internal Server Error

Problem in on line 18. fix is:
my $str = DBI::neat_list([EMAIL PROTECTED], 30, " "); 


-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Why undef array has an element?

2004-06-04 Thread WilliamGunther
In a message dated 6/4/2004 3:31:51 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>I've read that
>
>@a = undef;
>
>creates an array with 1 empty element.  Why does it do so?  (I'm trying to
>learn to think like Perl, not just learn it by rote.)
>

The best way to think of it, I think, is that parenthesis are optional for 
lists. It's necessary, however, for more than one item when assigning a list to 
an array because precedence dictates that the comma (,) binds looser than the 
equal sign (=). 

So 
@a = undef;
is actually evaluated as 
@a = (undef);

and something like 
@a = undef, 2;
is actually evaluated as 
(@a = (undef)), 2;


-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: a simple question

2004-06-16 Thread WilliamGunther
In a message dated 6/16/2004 12:10:54 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>Thanks in advance for your kind help.
>
>For the following string: 
>
>" axyzb  cxyzd "
>
>What is the command to extract the substrings with "xyz" in them? In this 
case, I'd like to >get two strings "axyzb" and "cxyzd".

Untested:

 my $t = ' axyzb  cxyzd ';
 my @matched = ($t =~ /([^ ]*xyz[^ ]*)/g);


-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: making print not wantarray

2004-06-17 Thread WilliamGunther
If the enduser programmer want to force it into scalar context they can:
print scalar fooyou();

-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 


Re: making print not wantarray

2004-06-17 Thread WilliamGunther
In a message dated 6/17/2004 5:32:16 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>I knew about that but the problem is most of the users (incuding myself 
>;p) will want to print it without the same $header info twice and don't 
>want to have a bunch of print scalar whatevr();
>
>If there is no way to tell if fooyou() was called in 'print context' 
>then we'll just use scalar, but I was hoping there was a way to tell...
>
>like this would be super nice if such a beast as wantprint existed...
>
>return "$header$data1$data2" if wantprint;
>return ("$header$data1","$header$data2") if wantarray;
>return "$header$data1$data2";

There is no such thing as print context. As it says in perlfunc
"Because print takes a LIST, anything in the LIST is evaluated in list 
context, and any subroutine that you call will have one or more of its expressions 
evaluated in list context."

-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: array

2004-06-18 Thread WilliamGunther
In a message dated 6/18/2004 3:37:17 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>- is it possible to search an array for a certain element, and that the 
>search returns the element index? eg. searching for 156 in the array 
>(123, 456, 156, 1354, 35164, 654656, 654, 846) should give 2
Look into List::Util (first() function)

-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: sort files by extension

2004-07-28 Thread WilliamGunther
In a message dated 7/28/2004 12:41:43 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
Transformation 
>@input = map { $_->[0] }
>sort { lc($a->[1]) cmp lc($b->[1]) }
>map { m/\.([^.]+)$/ ? [$_, $1] : [$_, ''] } @input;

Maybe I'm missing something but since you're doing Schwartzian Transformation 
already why call lc() every time?

@input = map { $_->[0] }   
  sort { $a->[1] cmp $b->[1] }
  map { m/\.([^.]+)$/ ? [$_, lc($1)] : [$_, ''] } @input;

--
-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: using a string as a scalar under strict

2004-07-28 Thread WilliamGunther
In a message dated 7/28/2004 4:28:12 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>The followin code doesn't work if I use strict. Is the only solution not to
>use strict.
>#!/usr/local/bin/perl
>use strict;
>my $blues;
>$a = "blues";
>$blues = "jazz";
>print ${$a};

 
This is using a soft, or symbolic, reference. Avoid using them. perldoc 
perlref explains:

[Symbolic References are] powerful, and slightly dangerous, in that it's 
possible to intend (with the utmost sincerity) to use a hard reference, and 
accidentally use a symbolic reference instead. To protect against that, you can say 
use strict 'refs';


--
-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 


Re: How to pass two arrays as arg in a subroutine?

2004-08-05 Thread WilliamGunther
Have them pass the arrays as a reference. For example:

@array1 = (1, 2, 3, 4, 5);
@array2 = (6, 7, 8, 9, 10);
mysub([EMAIL PROTECTED],[EMAIL PROTECTED]);

sub mysub{

 my ($array1, $array2) = @_;   
  #process @{$array1}
  #process @{$array2} etc
  return @array3;
}

Look into perldoc perlref

Prototyping is another option, not entirely recommended unless it's entirely 
needed. perdoc perlsub for more info.

--
-will 
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Two easy questions.

2004-09-20 Thread WilliamGunther
You appear to be on a Windows system. The file  extensions on Windows are for 
association. Hence, to answer your second question  first, if you're on 
ActiveState Perl, all .pl extensions are automatically  associated with perl, if 
you did it right, and just typing 'foo.pl' in the shell  should run it. .cgi, 
.pl, etc. It doesn't matter to the interpreter. It may  however matter to how it 
is treated by the OS and other programs, such as a  server.

--
-will 
http://www.wgunther.tk
(the above message is  double rot13 encoded for security reasons)

Most Useful Perl  Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite   


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: PROTO in sub NAME (PROTO) {

2004-09-21 Thread WilliamGunther
Prototyping can be useful in Perl. It shouldn't be overused, however. They  
can be powerful when trying to make functions that look and feel like 
built-ins.  Trying to, for example, create a subroutine that looks like map, grep, and 
sort  is made by prototyping it as (&@) (will pass coderef and an array). If 
you  want to accept an array and handle it like splice does you can do (\@;@)  
(will pass array ref and an optional array). 
 
There are very specific examples found in the manual in perldoc  perlsub.
 
And there is a warning IF the subroutine is declared before you call  it.
 
Prototyping(1,2);  #No exception, just a warning
 
sub Prototyping ($$$) {
print pop;
}
 
Prototyping 1, 2, 3; #Good job
&Prototyping(1,2); #works, read perldoc perlsub
Prototyping(1); #Death
 
I'm an advocate of prototyping. I like the power it can display in making  
your own functions behave like built-ins. But you can't go crazy with it and  
prototype every sub you write. Only do it when it makes your and the  
enduser's/maintainer's life easier.

--
-will  
http://www.wgunther.tk
(the above message is double rot13 encoded for  security reasons)

Most Useful Perl  Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]