On Jun 4, Satheesh Ramakrishnan said:
>How do I assign 1298b to some scalar variable from the string below.
>
>context_config_file = "1298b";
You probably want to use a hash of configuration variables, not a lot of
scalars.
There are modules for parsing simple config files, but if you want to d
On Jun 4, David Gilden said:
>Which perldoc will list the command line switches?
Try 'perldoc perl', and you'll see listed:
For ease of access, the Perl manual has been split up into a
number of sections:
perlPerl overview (this section)
perldelta
On Jun 4, [EMAIL PROTECTED] said:
>hello all-
>just a question concerning convention and accepted syntax.
Most people suggest the standard CGI.pm module, which allows you to do
things like this:
use CGI 'param';
if (my $flavor = param('ice_cream')) {
# do something with their favorite
On Jun 4, Pedro A Reche Gallardo said:
>perl -ne 'BEGIN{$/=">"}if(/^\s*(\S+)/){open(F,">$1")|| warn"$1 write
>failed:$!\n";chomp;print F ">", $_}'
>This command will take a file like this:
>name1: anything
kdkdkkdkk
dkdkkdkdk
>name2: anything
slkslsksksl
>and convert it into two files, named
On Jun 4, Nichole Bialczyk said:
>i'm curious as to how secure flock is. if the file is locked and another
>user tries to access it, does it wait or does it kick them off? also, is
>it ever possible for it to get stuck?
First, let me tell you that flock() doesn't really produce "file
locking"
On Jun 4, Tony Cook said:
>On Mon, 4 Jun 2001, George Petri wrote:
>
>>
>> In a book called "Open Source Linux Web Porgramming" by Jones and Batchelor,
>> it says (on Page 61):
>
>If your book says this, then it's wrong on 2 counts, both of which you
>seem to have discovered yourself:
Perhaps
On Jun 3, Abdulaziz Ghuloum said:
>Incrementing and decrementing strings are quiet puzzling to me. I don't
>seem to figure out the rationale behind the use of the increment (++)
>and decrement (--) operators when it comes to strings. Let me
>illustrate:
Here's the short answer:
Auto-increment
On Jun 3, [EMAIL PROTECTED] said:
>Could someone please explain this to me clearly so I
>can actually understand word boundaries?
I've tried to do this in Chapter 3, "Extending and Controlling", of my
upcoming book, "Regular Expressions in Perl". If you read it, it might
help shed some light on
On Jun 3, Richard Hulse said:
>I have a module which overloads a few operators
>
>snippet:
>use overload
> "+" => \&addoffset,
> "-" => \&subtractoffset,
> q("") => \&printit;
>
>Even if I allow Perl to magically make the += happen for me it still does
>the same (wrong) thing.
Are y
On Jun 3, M.W. Koskamp said:
>> #sample of the text
>> Nitrogen 0.0 -5.78 0.0 0.0 0.0
>>
>> #sample of the program.
>> while(){
>>
>> if (/(Nitrogen) *([0-9.\-]*) *([0-9.\-]*) *([0-9.\-]*) *([0-9.\-]*)
>> *([0-9.\-]*)
>> /) {
>> if ($2 <= 0.0) {
>> $name = $1; $nitrogen1 = $2; $nitrogen2 =$3;
On Jun 2, Chas Owens said:
>On 02 Jun 2001 01:19:35 -0700, Paul Fontenot wrote:
>> It is a system logfile. That is the way syslog is dumping it into the log.
>
>Can you give an example of a line from each month?
The file has two spaces before the 10th of every month. That's more like
1/3 of the
On Jun 1, [EMAIL PROTECTED] said:
>$i = 1;
>$power = 1;
>
>print "Input a number:\n";
>chomp ( $x = );
>
>print "Input the value you want the number raised to\n";
>chomp ( $y = ) ;
>
>while ( $i<= $y ) {
> $power *= $x;
> ++ $i;
>}
This loop is basically a for-loop in extende
On Jun 2, David Gilden said:
>Is one of these preferred over the other?
>
>while(){
>push(@everyline, $_);
> }
>
>$longstring = join("",@everyline);
>@oldentries = split(//,$longstring);
It's kinda silly to make an array, just to join the elements together
later. Use a strin
On Jun 1, David Gilden said:
>$sort_order =0;
>
>$sort_type = ($sort_order) ? 'Newest First' : 'Oldest First';
># are the () optional?
In this case, yes, you don't need those parens.
>print ($sort_order) ? 'Newest First' : 'Oldest First';
Remove the parens, or add them around the entire argume
On Jun 1, [EMAIL PROTECTED] said:
>I want to take the output of a df -k command and take the first column
>and put it into a nice array or list that I can then later put each
>seperate line into a command. I have tried a few different versions and
>can't figure it out. I'm new to this and I'm su
On Jun 1, Steve said:
>use File::stat;
>use time::local;
Heh, that's windows for you.
use time::local;
works on windows, but you meant to write
use Time::Local;
You see, on windows, 'time/local.pm' and 'Time/Local.pm' are the same
thing, because the OS is case-insensitive. However, when
On May 31, Brian Shoemaker said:
>($id,$dir,$code,$etc) = split(/\|/,$i);
>
>However, the Perl 5 book I have lists the syntax of split as.
>
>lvalue = split(/pattern/,expression,maxSplit);
Perl can automatically add that argument if you have a known number of
elements on the left-hand side:
On May 31, Paul said:
>Still, though, won't that return all the *strings* as elements, rather
>than the individual characters? and wouldn't \S* solve that difference?
We're only matching ONE character at a time:
@all_chars = $str =~ /./sg;
@all_ws = $str =~ /\s/g;
@all_non_ws = $str
On May 31, Paul said:
>> my @chars = $string =~ /\S/g;
>
>I've seen a couple of people doing this, and maybe I'm just confused,
>but
>
>Isn't the point of the original request to split into the original
>characters, but leave *out* the spaces?
>
>and isn't \S any nonspace?
>
>So, if you split
On May 31, Brett W. McCoy said:
>> NEVER tell a random browser what your error message is!
>>
>> AT BEST, you simply say "it broke, we know about it, sorry".
>
>The Koi or Mortal Kombat modules are good substitutes. :-)
Heh, I think you mean Coy. Koi is a type of fish. ;)
Coy (by Damian Conway
On May 31, Pedro A Reche Gallardo said:
>How can I split a string of caracters -any but blank spaces- into
>the individual caracters?
So you want to split "what's up, doc?" into
@chars = qw( w h a t ' s u p , d o c ? );
That is, every character except spaces?
First, remove spaces from t
On May 31, Randal L. Schwartz said:
>>>>>> "Jeff" == Jeff Pinyan <[EMAIL PROTECTED]> writes:
>
>Jeff> A closure is an ANONYMOUS function (constructed via $x = sub {
>Jeff> ... }) that contains LEXICAL variables that have been defined in
>Jeff&
On May 31, Ahmer Memon said:
>Later on I noticed the sprintf function. You can use this to format your
>dates and times without cycling through all the elements returned by the
>localtime function. Anyway I am pasting in a bit from one of my scripts
>that does just this:
>
>($sec,$min,$hour, $d
On May 31, David Gilden said:
>This approach of treating C and C like object methods
>calls doesn't work for the diamond operator. That's because it's a
>real operator, not just a function with a comma-less argument. Assuming
>you've been storing typeglobs in your structure as we did above, you
this has been helpful -- it might be a bit too
much for beginners that don't know much about scoping and references[3].
[1] perldoc -f my and perldoc -q lexical
[2] "Coping with Scoping", by Mark-Jason Dominus, Winter 1998:
http://perl.plover.com/FAQs/Namespaces.html
[
On May 30, Ravi Channavajhala said:
>Does anyone have a nifty way to do a sort and comparison of two or more
>hash keys with multiple values per key?
>push (@{$a{$b}},$c);
>$b keeps changing, lets say in first instance it is "1" and
>"2" in second instance, and each instance has multiple values
On May 30, [EMAIL PROTECTED] said:
>I'm new to the group and new to Perl and am very glad to have such a
>resource available. Hopefully someday I'll be on the giving end of the
>help list but for now I'm stumped. How do I test an input to see if it
>is a real number? I have a situation someth
On May 30, Jeffrey Goff said:
>It's a shortcut for assigning words to an array. That statement would return
>an array that looks roughly like this:
>
>('"stuff",', '"more stuff",', '"even more stuff"') # Note the double quotes.
Nope, no matter what you do, qw() really splits on whitespace.
f
On May 30, Walt Mankowski said:
>On Wed, May 30, 2001 at 01:47:55PM -0400, Jeff Pinyan wrote:
>> =head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod
>
>Looks like you're overdue for an upgrade... :-)
Not my machine, it's just the ISP I used to work at -- I h
On May 30, Wilson, Tom said:
>My two cents sometimes getting the answer is more important that
>learning it right away. There are many times in the various languages that
>I've worked with that I've gotten the answer and later on remembered the
>solution and incorporated it into something ne
On May 30, Peter Cornelius said:
>> if (@ARGV and -T $ARGV[0]) { ... }
>
>Just wondering if there is a reason for using the lower precedence 'and'
>here instead of '&&'? I haven't been finding many uses for 'and' which
>tells me I might not fully understand it.
You must be careful about using
On May 30, Scott Thompson said:
>While I couldn't agree more with both statements, I think it is the
>unfortunate reality that, with the recent (last 2 years... ) boom and
>subsequent bust of the Internet economy at large, there is a growing
>majority of beginning programmers who will fall into t
On May 30, Craig Moynes/Markham/IBM said:
>Is there anyway to sleep for less than a second using the default
>installation of perl ?
friday:~ $ perldoc -q sleep
=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod
=head2 How can I sleep() or alarm() for under a second?
If you want fin
On May 30, David Gilden said:
>$data = 'some
>multi line
>string';
>
>while($data){
> push(@everyline, $_);
>}
You're confusing this with
while () {
# do something with $_;
}
You can do:
@lines = split /\n/, $data;
or you can download the IO::String module from
On May 30, Peter Scott said:
>*Curiosity* is an essential trait for the programmer. In all seriousness,
>if you don't have a deep desire to find out how things work - in
>particular, software - this may not be the field for you. Principally
>because our tools are rarely so perfect at encapsu
On May 30, Paul said:
>Just an elaboration -- you can do this:
>
> @hash{ qw( a b c ) } = qw( 1 2 3 );
>
>which should give you the same as:
>
> %hash = ( a => 1, b => 2, c => 3 );
Only if %hash was previously empty. Assigning to a hash all at once
clears it and sets the key-value pairs you p
On May 30, Mark Salazar said:
>I was recently bitten by this, and it's not clear to me (and others) if
>this is correct Perl behavior or not.
>
>If you have a user defined function 'func' that returns a list and you'd
>like to sort that return value it's reasonable to try:
>
> sort(func(@list));
On May 30, Craig Moynes/Markham/IBM said:
>I have a script that when it runs (with no parameters) I have warnings
>displayed (we have all seen them but) :
>
>>Use of uninitialized value at ./log_prune.pl line 14.
Because @ARGV is empty, $ARGV[0] is undef.
>if ( (-T $ARGV[0]) )
Use:
if (@ARG
On May 29, George Balogi said:
>#!D:perl/bin/ -w
>cut -f3,5 -d"|" try
You appear to be writing shell code in Perl. Perl is not shell, and
vice-versa. Furthermore, cut isn't implemented in DOS (to my knowledge).
You need to basically write this as Perl code. Here are some helpful
hints:
*
On May 29, Me said:
>If you will allow perl to make use of temporary files
>behind the scenes (which is normally perfectly ok),
>Cookbook recipe 7.9 is a whole heck of a lot
>simpler. As a command line one liner:
>
>perl -pie 's/a/p/g' try.txt foo.txt
>
>will go thru files try.txt and foo.txt
On May 29, Walt Mankowski said:
>On Tue, May 29, 2001 at 11:59:18AM -0700, Randal L. Schwartz wrote:
>> > "Brett" == Brett W McCoy <[EMAIL PROTECTED]> writes:
>>
>> >> Uh, careful. This got added to 5.6.1 to support pseudo-hashes and is
>> >> probably coming back out when pseudo-hashes get
On May 29, Jie Meng said:
>I am a newbie. Would you please tell me how to delete an element in an
>Array?
The delete() function works on arrays (in Perl 5.6), but it doesn't remove
the element (unless it occurs at the end of the array).
You want to use the splice() function.
splice @array, $
On May 28, Bornaz, Daniel said:
>$stt="The food is under the bar in the barn in the river.";
>$stt=~/bar(.*?)river/;
>print "$&";
>
>The output is:
>bar in the barn in the river
>
>Instead of the expected:
>barn in the river
For the meantime, you might like to look at chapter 6 of "Learning Per
On May 26, Manoj Jacob said:
>I've done some programming in perl mainly for web oriented stuff
>There's one thing i've always wanted to understand...Sometimes the perl
>program ends with .pl and sometimes .cgimaybe i'm a very bad programmer
>and i'm really dumb that i've not understood th
On May 25, Keith A. Humphrey said:
>Is there a perl command that can tell me the age of a file?
Not on Unix. You might be able to get a Windows or Mac specific module to
get the creation date of a file on those systems, but Unix does not store
the creation date of a file -- you can, however, ge
On May 24, Jeff Pinyan said:
>Now the GRT looks like:
>
> @sorted =
>
># get rid of leading sorting string
>map { s/^\S+\s+// }
That should be
map { s/^\S+\s+//; $_ }
or even
grep { s/^\S+\s+// }
You can use grep() here since all lines will match tha
On May 24, Gustho said:
>Below is a sample directory listing of the mail folder
>on a Linux box, I would like to sort the same using
>the last field (ie. lward, ohara, dray) starting with
>the 2nd character (ie from ward , hara and ray) :
>
>-rw--- 1 lward mail0 May 24 15:43 lward
>-rw
On May 24, David Blevins said:
>So, as far as editing files in a subroutine of a script, there does not seem
>to be an easier or more performant way?
>
>Would it be performant to call the perl command as a subprocess, as in:
>
>`perl -ni -e 'print unless /I'm a bad line, delete me\./' thefile`;
On May 23, Andy Roden said:
>($router_table{i},$router_type{i}) = split(/\|/,
>$router_tables{i});
You probably want that to be $i, not i.
>if ($router_table{i} ne "") {
>print SH "\"$router_table{i}\" ";
>}
There too.
>else {
>print SH "\"$rout
On May 23, Tom Yarrish said:
>Been reading the list for a little while, and had sort of a philosophy
>question for the group. I've been trying to learn Perl for some time
>(in fact, my company has offered to pay for me to take a Sun course on
>it). In the mean time I've been reading through the
On May 23, Paul said:
>{ local @ary = $hash_name->{arrayref}; # @ary now the array
> print $ary[4]; # access is "normal"
>} # aliasing ends with scope
Err, I think you mean
local *ary = $hash_name->{arrayref};
That will make @ary an
On May 23, Peter Cline said:
>Does anyone know a better way to say @{$$hash_name{arrayref}}?
Doing $$foo{...} or $$foo[...] is often confusing for people to read.
That's why the -> operator exists:
$foo->{bar} # is like $$foo{bar}
$foo->[$i] # is like $$foo[$i]
So you could write:
@
On May 23, David Gilden said:
>#!/usr/bin/perl
>
>$test = "dave David Davy";
>
>$i=0;
>
>### Does not work want to count the number of matches...
>$regex= ($test=~ s/(dav)/$i++ $1/eig);
>
>print "$regex $i\n";
Do you want to count matches, or change the string? If you just want to
count th
On May 23, Timothy Kimball said:
>2. Use the "s" modifier to treat the slurped-up file as a single string.
The /s modifier changes the meaning of . only, and not ^ or $ -- see my
response.
See chapter 5 of LPRE:
http://www.pobox.com/~japhy/docs/LPRE.html#5.%20more%20pattern%20modifiers
--
On May 23, pda said:
> and come to the new line and also check whether if there is a in
>the given file if it finds it has to replace with a other string.
>
>this is what i tryed on the command prompt.
>
>perl -pi -e 's{^
On May 23, Kyrytow, Stefan said:
>Why they are called Regular Expressions, I am not to sure. They should be
>called Frustrating Expressions.
You might want to take a look at
http://www.pobox.com/~japhy/docs/LPRE.html
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~j
On May 23, Randal L. Schwartz said:
>>>>>> "Jeff" == Jeff Pinyan <[EMAIL PROTECTED]> writes:
>
>Jeff> if (length($x) and $x =~ /\D/) { fail() }
>
>Simpler...
>
>if ($x =~ /\d/ and $x !~ /\D/) { winner! }
Yeah, I was thinking of t
On May 23, Jos Boumans said:
>Or a really one:
>
>if ($x =~ /\D/) {
>print "found non digit, do not pass go, no 20 grands for you";
>} else {
>print "good boy";
>}
>
>where \D stands for NON digits
The only problem is that "" passes that regex. For that reason, I would
suggest something
On May 22, Peter Cline said:
>> @parts = split ' ', "this and that";
>> { local $" = ") ("; print "(@parts)"; }
>> # (this) (and) (that)
>
>Will the ") (" assign any amount of space to the list separator?
>This is interesting. I haven't encountered this syntax before.
Using split ' ' is
On May 22, Peter Cline said:
>Try this.
>my $text = "Browser/Version Platform";
>my ($keep,$discard) = split / /, $text;
>print "$keep\n";
>
>This splits on space and saves the part you want to the variable $keep and
>the rest to $discard.
Actually, it splits on EXACTLY one space. That can cau
On May 21, Paul Cotter said:
>> The problem is: PROTOTYPES MUST BE SEEN BEFORE THE FUNCTION IS CALLED.
>
>I've seen this statement before and do not really understand it, having come
>from a 'true-compiler' background. It is the 'seen' that puzzles me.
>
>If I have a 'require' then I believe the
On May 22, Richard Thompson said:
>We have moved a website off a server outside our offices to one inside.
>everything went fine but one of our cgi is not working so using some
>info shared in this forum we tried to run from the command line. now
>here is the problem we cannot get it to pass the
On May 22, Paul said:
>I know that in many C compilers, the a ? b : c construct with the
>ternary ?: operator si not stable after the second or third nesting,
>but I've never seen that sort of problem in tests I've run in Perl.
The only to watch out for is precendence:
$a ? $b = $c : $b = $d;
On May 22, Mark on GCI Server said:
>open(TESTER, "print "Enter a username: ";
>$input = ;
You need to chomp $input, since it has a newline at the end.
>$x = 0;
>$y = 0;
>$w = 0;
>$z = 1;
>if ( ne "") {
That reads a line (and it is lost forever).
>while($line = ) {
>c
On May 22, Mark on GCI Server said:
> I'm trying to populate an array from a file, I think I've got the array
>populated, however, I'm not sure. I then want to compare an input against
>the array to determine if its there, then look at the second component of
>each record. Any assistance would
On May 21, Laurent Marzullo said:
>Insecure dependency in mkdir while running setuid at
>.../File/Path.pm line 137
>sub create_rcsdir
>{
> local( $cctrl , $group ) = @_;
> local( $rcsdir ) = $ENV{ RCSDIR };
>
> mkpath( $rcsdir , 1 , 0750 );
>}
I bet the problem is due to
A rather scantily clad review is at
http://www.pobox.com/~japhy/perl/judfr.txt
There's not much to see, because I'm not really sure I understand the data
structure (or rather, its makeup and purpose), but I do have a couple of
comments about things I would do differently.
--
Jeff "japhy" Pin
On May 19, Aaron Craig said:
>
>sub PassAnEntireArray(@)
> {
> my(@array) = @_;
> ...do some stuff...
> }
>
>sub PassAnArrayRef($)
> {
> my($ar) = @_;
> ... do some stuff...
> }
>
>I assume passing array refs (and hash refs for that
On May 18, Wagner-David said:
>$_ will have the carriage return as part of the name, so should do a chomp
>before putting in the hash otherwise would have to have the carriage rturn
>as part of the testing process and I don't think you want that. So the line
>right after , place a chomp.
I beg t
On May 18, Yacketta,Ronald J said:
>Is this error version specific?
>syntax error at ./wki.pl line 101, near "tr/ //d for "
>Execution of ./wki.pl aborted due to compilation errors.
... for LIST;
was added in 5.005, so for 5.003, you'll need to do:
for (LIST) { ... }
--
Jeff "japhy" Pin
Here's my "vision" of the new program:
http://www.pobox.com/~japhy/perl/wki-new.txt
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://
My review is at:
http://www.pobox.com/~japhy/perl/wki.txt
I will have a bit of a rewrite demonstrating some of the points raised in
my critique at a similar URL in a few minutes.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlm
On May 18, Yacketta,Ronald J said:
>Do you mind if I post a script I have been hacking away at for a week or
>so now? I really would like input to improve its performance etc, I am
>using this script as my tutorial. I have learned a great deal from this
>list and by hacking away.
I think code re
On May 18, Liger-dc said:
>I'm currently copying two 1-dimensional arrays using
>for loops. Is there an easier way as this may tag my
>cpu due to the huge numbers I am using.
What's wrong with:
@foo = @bar;
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are
On May 18, David Merrill said:
>$title =~ s/\s*$//;
>
>where $title = "The Linux Programmer's Guide "
>
>and it is being truncated after the ' mark. All I want to do is remove
>the trailing spaces from the string. Can someone please help?
You've already solved your problem about single q
On May 18, Paul said:
> @hits = grep /^$TEST1$/, @HOLDER;
Do not use a regular expression to check for equality. It breaks far too
often.
* the $ anchor does not match the end of the string -- it matches the
end of a string OR before a newline at the end of a string
* if $TEST1 has any
On May 18, John Storms said:
>Not the best code, but it works fine.
>
># roundup(,[]);
># returns a truncated and rounded up value.
>sub roundup {
>my($i); for($i=0;$i$char = substr($num,$i,1);
>$next = substr($num,$i+1,1);
Rounding numbers shouldn't be a
On May 18, Craig Moynes/Markham/IBM said:
>I looked through my book (perl nutshell) and PP has not arrived yet, so I
>will ask here.
>
>I have an number that needs to be rounded to the nearest whole number.
>This is my solution:
Timothy Kimball has a good solution, but I have a generalization:
On May 17, Yacketta,Ronald J said:
>backint:maple aspen pine
>online:orange palm cherry
>
>is it possible to read in this file and what ever is before the : would
>become the name of
>the array?
The key is, DON'T DO THAT. Don't make arrays with names you don't know
ahead of time. It's best to
On May 17, [EMAIL PROTECTED] said:
> $
> Contains the subpattern from the corresponding set
> of parentheses in the last pattern matched, not
> counting patterns matched in nested blocks that have
> been exited already. (Mnemonic: like \digits.
On May 17, Peter Cornelius said:
>$returnCode eq "o.k." ? $subject .= " -OK-" : $subject .= " -FAILED-";
You're being bitten by precedence. ?: is stronger than .=, so your code
is like:
($foo == 1 ? $bar .= "this" : $bar) .= "that";
Which means that if $foo is 1, $bar gets "thisthat" tacked
On May 17, Doug Johnson said:
>my $x = "return";
>
>if (($x = "a") || ($x = "test" ) || ($x = "return" ) || ($x = "x-retun"))
> {
> print("bunch of foo);
> }
First, that's NOT the code you have. If it IS, it's broken.
if ($x eq 'a' or $x eq 'test' or $x eq 'return' or $x eq 'x-retu
On May 17, Paul Johnson said:
>You can't. You are trying to use symbolic references and when you have
>strict turned on you are promising not to do that.
>my $varname = "myvar";
>{
>no strict "refs";
>no strict "vars";
>@$varname = ('a','b','c');
>}
It's important to know one thing
On May 17, Alberto Manuel Brandao Simoes said:
>RULE ---> FILE*
>
>::t {
> for (@FILE) {
> #do something
> }
>}
>
>The idea is, when parsing the RULE, create the FILE array so that the user can
>browse it. This is done by an eval, so I can construct a string initializing
On May 16, jane doe said:
>How do I remove duplicate items from an array? I apologize for being a
>"newbie". :)
Please read 'perldoc -q duplicate' or 'perldoc -q unique'. You can see
these answers in Perl FAQ #4, online at http://www.perldoc.org/, or on
your computer via the 'perldoc' command.
On May 16, Liger-dc said:
>are the variables $1 and $2 special variables? and if
>so what do they do?
Read perldoc perlvar:
$
Contains the subpattern from the corresponding set
of parentheses in the last pattern matched, not
counting patterns matched
On May 16, Paul said:
>"or" also short circuits, and some consider it more readable, but it
>(and the "and" operator) always return(s) a boolean value, while ||
>(and &&) return the value of the first true expression.
>
> $a or $b # returns 1 if either has a non-false value, else ''
> $a || $b
On May 15, Liger-dc said:
>What does the following formatting do?
>
>$line =~ /^; .ot (\d+)/)
I suggest you download YAPE::Regex and YAPE::Regex::Explain from CPAN --
the 'explain' program automatically generates an explanation for a regex:
friday:~ $ echo '^; .ot (\d+)' | explain
The regular
On May 15, Paul said:
>
>--- Peter Cornelius <[EMAIL PROTECTED]> wrote:
>> The doesn't read into $_. You can add a 'print $_;' in there
>> to verify it. I think you're getting confused by the
>>while(){...}
>> structure. This puts the result of the readline into $_ for you if
>> the is t
On May 14, Noah Sussman said:
>I am trying to write a simple script to insert ALT attributes into IMG tags
>that don't have them, leaving other IMG tags untouched.
>
>The problem is that I can't figure out how to tell Perl to search for
>strings beginning with "" AND not containing "ALT="
>(and i
On May 15, King, Jason said:
>>A rather clever way to emulate locking is to use mkdir() and rmdir().
>>
>>Although it requires you to create a lock file, it's atomic and safe.
>
>are you sure ? .. just because it constitutes one Perl statement doesn't
>mean that it's atomic .. I suspect mkdir has
On May 14, Peter Scott said:
>Ooh, that is clever. Has it been encapsulated in a CPAN module?
No. It can break on NFS.
>> 1 until mkdir "$_[0].lck", 0777;
>
>Perhaps sleep 1 until mkdir would be a little less stressful on the average
>system :-)
Feh. ;)
--
Jeff "japhy" Pinyan [EM
On May 14, Brian Shoemaker said:
>The Perl 5 book I have says flock function doesn't work in Windows systems.
>
>I don't want to create a lock file each time someone accesses a file and
>then have to delete that lock.
A rather clever way to emulate locking is to use mkdir() and rmdir().
Althoug
On May 14, Paul Cotter said:
>next if /^#?$/; # skip empty lines and comment lines
No. I had a bad regex weekend (as Paul could personally attest to).
The author asked the same question.
next if /^(#|$)/;
will work, as well
next if /^#/ or /^$/;
I'm sorry about the mixup. I had origi
On May 13, Jeff Pinyan said:
>if (/(?:^|\@)(\S+)/) {
I had a precedence error in my code here. That regex will match at the
beginning of the line every time. It should be:
if (/\@(\S+)/ or /(\S+)/) {
# ...
}
Sigh. And I'm writing a book about these. I should ge
On May 13, Thomas Leuxner said:
>#mydomain.com
>mydomain.com anything
>[EMAIL PROTECTED] tlx
>
>#newdomain.com
>newdomain.com anything
>
>
>#somewhere.com
>somewhere.com anything
>
I suggest you make a hash of array reference
On May 12, Pam Derks said:
>I'm a newbie struggling to total up a web users survey for work. The
>HTML form is a separte document, which calls up the cgi script. I've
>been reading the CGI module and figured out how to get the key/value
>paris. Now, I want to tally the answers, i.e. 10 users cho
On May 11, FLAHERTY, JIM-CONT said:
>$test1 = s/<>//g
^
This gives an error.
s!<>!!g;
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Gr
On May 11, Gross, Stephan said:
>I wasn't clear last time. I wrote:
>>I want to match the following:
>>1) the letters "PT"
>>2) a space or nothing
>>3) a word that may or may not be in parentheses or even not exist
>>and return item #3 (which may be null)
>>Example:
>>PT (XYZ) or PT XYZ or PTXYZ
On May 11, Paul said:
>> That sorting method does a lot of work -- that is, it does things
>> more than once. I suggest you use a schwarztian transform, or the
>> Orcish maneuver, to increase speed.
>>
>> {
>> my %cache;
>> @new = sort {
>> ($cache{$a}) = $a =~ /\@([^:]+)/ if no
1 - 100 of 132 matches
Mail list logo