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

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 r

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 perl

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,

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 Schwart

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 Lo

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

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 -

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 st

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 th

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

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 f

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.w

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

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

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, { '^[^\.]+

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 CG

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 = >MT

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 Getop

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 =

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

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 mod

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 p

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

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 i

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{use

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

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 referen

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 $@

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

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

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

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 arg

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.

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 =

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 perl

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 s

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,

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($sc

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 Cry

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. s

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] writ

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

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 fil

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

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 i

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

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 co

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 ---

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 } } B

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]

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: 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 b

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: 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: 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

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,

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.