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
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
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
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,
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
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
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
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
-
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
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
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
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
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
>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
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
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, {
'^[^\.]+
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
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
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
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 =
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
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
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
>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
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
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
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
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
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 $@
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
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
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
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
>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.
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 =
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
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
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,
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
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
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
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
$| = 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
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
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
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
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
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
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
---
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
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]
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.
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
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
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
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
#!/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,
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.
58 matches
Mail list logo