[18039] in Perl-Users-Digest
Perl-Users Digest, Issue: 199 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 2 09:05:31 2001
Date: Fri, 2 Feb 2001 06:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981122709-v10-i199@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 2 Feb 2001 Volume: 10 Number: 199
Today's topics:
ActiveState Perl Threads <kevin.murphy@jhuapl.edu>
Re: Calling all DB_File Gurus. (Anno Siegel)
Re: Calling all DB_File Gurus. (Garry Williams)
Re: dealing with the gaps nobull@mail.com
Re: first real PERL script . . . <bart.lateur@skynet.be>
getting file permissions and owner on ufs <andre.bonhote@linux.ch>
Re: getting file permissions and owner on ufs (Anno Siegel)
Re: getting file permissions and owner on ufs <andre.bonhote@linux.ch>
Re: Handling Errors nicely (Matt Venn)
Re: Linux does reclaim memory from perl <news@brueck.muc.de>
matching integer's and end of a string problem (jay)
Re: matching integer's and end of a string problem (Bernard El-Hagin)
Re: matching integer's and end of a string problem <tom@power.net.uk>
Re: matching integer's and end of a string problem (Abigail)
Re: matching integer's and end of a string problem (Bernard El-Hagin)
Re: matching integer's and end of a string problem (Jay Bowers)
Re: matching integer's and end of a string problem nobull@mail.com
Re: matching integer's and end of a string problem mexicanmeatballs@my-deja.com
Re: Opera Hotlist To HTML (Abigail)
Re: Possible buggy behavior in File::Find nobull@mail.com
regexp <robert@NOSPAMcrazymoose.co.uk>
Re: regexp (Anno Siegel)
Re: Sting validation question...? (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 2 Feb 2001 08:21:59 -0500
From: "Kevin Murphy" <kevin.murphy@jhuapl.edu>
Subject: ActiveState Perl Threads
Message-Id: <95eca3$i7u$1@houston.jhuapl.edu>
Does anybody know if ActiveState Perl 5.6.623 for
Win32 was really compiled for thread support??
The install fill claims "multi-threaded", as does a quick
"perl -v", but any script I try to run with threads yields
a "No threads in this perl at line X". (Win2000)
Even just using the incredibly simple sample scripts
from the perldocs.
Kevin Murphy
------------------------------
Date: 2 Feb 2001 11:11:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Calling all DB_File Gurus.
Message-Id: <95e4ku$iko$1@mamenchi.zrz.TU-Berlin.DE>
Jody Fedor <Jodyman@usa.net> wrote in comp.lang.perl.misc:
>
>Anno Siegel wrote in message <95bj9j$f6n$1@mamenchi.zrz.TU-Berlin.DE>...
>>
>>Try $c = tie @database, 'DB_File', ....;
>>
>>and then do whatever you want to do to $c. This way you will be
>>modifying the actual object the database is tied to.
>>
>>Anno
>
>Thanks, and I'll do that! First time using DB_File and the docs aren't that
>good.
Your problem didn't come from a lack in the DB_File docs, but from
a lack of understanding of the tie() process on your part. Reading
a bit more about tie() might have helped more than the guesswork
your code was based on. But you'd probably claim that those docs
aren't "that good" either. Oh well...
Anno
------------------------------
Date: Fri, 02 Feb 2001 13:53:40 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Calling all DB_File Gurus.
Message-Id: <EZye6.465$Sn3.18267@eagle.america.net>
On Fri, 2 Feb 2001 01:03:33 -0500, Jody Fedor <Jodyman@usa.net> wrote:
>Anno Siegel wrote in message <95bj9j$f6n$1@mamenchi.zrz.TU-Berlin.DE>...
>>
>>Try $c = tie @database, 'DB_File', ....;
>>
>>and then do whatever you want to do to $c. This way you will be
>>modifying the actual object the database is tied to.
>>
>>Anno
>
>Thanks, and I'll do that! First time using DB_File and the docs aren't that
>good.
I've never used the DB_RECNO file type in DB_File, but I've used
DB_HASH and DB_BTREE extensively and never found a problem with the
documentation. So I decided to look at the manual page for DB_File.
The second example in the RECNO section clearly used the tied
reference when opening the database. Indeed the SYNOPSIS section
clearly shows how to call tie, taking the tied reference for all three
types of files. I may not even have looked at the RECNO section
because the SYNOPSIS seems very clear to me. There is a section that
discusses creating extra instances of the "type/openinfo" data
structure used as the last parameter to tie(). The DB_File::RECNOINFO
constructor can be used, if you want to set bval before calling tie().
But that section makes it clear the once you have done that, it's to
be used for the last parameter to tie().
I wonder what part of the "docs aren't that good"?
--
Garry Williams
------------------------------
Date: 02 Feb 2001 11:07:59 +0000
From: nobull@mail.com
Subject: Re: dealing with the gaps
Message-Id: <u9hf2dfils.fsf@wcl-l.bham.ac.uk>
ange@cybernospampage.co.uk (Ange) writes:
> The product names contain gaps ie R679:Adraplan Model 769, but
> unfortunately the perl script only produces R679:Adraplan.
>
> It works if I change the product name to R679:Adraplan-Model-769.
>
> Can anyone sugggest a reason for this happening,
Probably splitting input file on whitespace when you probably want to
be splitting on some delimiter. Quite possibily on comma when it does
not appear inside quotes (see FAQ).
> or location for a script which can do the job?
Planet Earth. I realise that's not a terribly precise location but
it's about as precise as the specification you've given of "the job".
------------------------------
Date: Fri, 02 Feb 2001 13:41:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: first real PERL script . . .
Message-Id: <tddl7tkv1772g3adg6l4q6ff95uopu31tu@4ax.com>
Stephen S. wrote:
>#assigning "Top of file" to an array for later printing
>@top = (
>"\x03\x65\x01\x1c\xff\x00\x00\x00\xc1\x00\x4b\x00\x00\x00\x00\x00",
>"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>"\x44\x41\x54\x45\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x00",
>"\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>"\x54\x49\x4d\x45\x00\x00\x00\x00\x00\x00\x00\x43\x00\x00\x00\x00",
>"\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>"\x44\x45\x53\x43\x52\x49\x50\x54\x00\x00\x00\x43\x00\x00\x00\x00",
>"\x2d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>"\x46\x49\x4c\x45\x5f\x4e\x41\x4d\x45\x00\x00\x43\x00\x00\x00\x00",
>"\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>"\x44\x45\x4c\x45\x54\x45\x00\x00\x00\x00\x00\x43\x00\x00\x00\x00",
>"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>"END"
>);
Holy macaroni! What kind of junk is that! Are you sure these aren't just
binary representations of numbers? Constructing these strings with
pack() might then be easier.
And drop that "END". You don't print it, so don't put it there.
>#assigning "End of Record" to an array for later printing
>@EOR = (
>"\x0d"
>);
>
>#assigning "End of file" to an array for later printing
>@EOF = (
>"\x0a"
>);
As someone else wrote: no need to use an array. Use a scalar: $EOR and
$EOF. Oh BTW, it looks as if you need to apply binmode() on your output
file handle.
>#Printing the top of the file . . .
>#Followed by an EOR Flag (seperator) . . .
>$i = 0;
>$done = "no";
>
>while ($done eq "no") {
> if ($top[$i] eq "END") {
> $done = "yes";
> } else {
> print FILE $top[$i];
> $i = ++$i;
> }
> }
My my my. Much too C-ish. Simply do
print FILE foreach @top;
or even
print FILE @top;
I'm not even sure why you didn't make @top into one large string.
BTW you set an explicit $done flag. No need, ever, because Perl has the
"last" keyword to jump out of a loop.
>print FILE $EOR[0];
>print "Sucessfully printed TOP of file . . .\n";
If you replaces @EOR with $EOR:
print FILE $EOR;
>open (FILELIST, $filename) || die "[OLD MAIL]Can't open old mail list.
>Aborting . .";
>
>while ($file = <FILELIST>) {
> chomp $file;
> $file_length = length($file);
>
> if ($file_length > 8) {die "\n\n[OLD MAIL]File names are too long.
>Aborting . .";}
>
> if ($file_length eq 8) {
> date_time_stamp();
> print FILE "$file. N";
> } elsif ($file_length eq 7) {
> date_time_stamp();
> print FILE "$file . N";
> } elsif ($file_length eq 6) {
> date_time_stamp();
> print FILE "$file . N";
> } elsif ($file_length eq 5) {
> date_time_stamp();
> print FILE "$file . N";
> } else {
> die "[OLD MAIL]File names are too short.\nThere may also be a
>problem with the FILES.NEW. Aborting . .";
> }
> }
>print "Sucessfully printed mail records to file . . .\n";
Gee. it looks like you want == for equality test, not eq.
>#Printing corect end of file flag
>print FILE $EOF[0];
That is
print FILE $EOF;
if @EOF got replaced by $EOF.
>print "Sucessfully printed EOF flag . . .\n";
>close FILE;
>close FILELIST;
>
>
>sub date_time_stamp {
>#Dealing with Time and Date . . .
>
>#load variable with localetime values
>($sec,$min,$hour,$dayofmonth,$month,$year,$wday,$yday,$isdst) =
>localtime(time);
You don't need time(). But, if this script takes a while, all mails can
get different timestamps. Is this what you want? Otherwise, replace time
with $^T (time of start of script).
>#year and month start at 0 due to perl being unix native
>
>$year = ($year +1900);
$year += 1900
>$month = ($month + 1);
$mont++;
>#print out date correctly
>
>if ($month >= 10 && $dayofmonth >= 10) {
> print FILE " $year$month$dayofmonth";
> } elsif ($month >= 10 && $dayofmonth <= 9) {
> print FILE " $year$month","0","$dayofmonth";
> } elsif ($month <= 9 && $dayofmonth >= 10) {
> print FILE " ";
> print FILE (($year),"0",($month),$dayofmonth);
> } elsif ($month <= 9 && $dayofmonth <= 9) {
> print FILE " ";
> print FILE (($year),"0",($month),"0","$dayofmonth");
> }
Wow wow wow. You probably want (s)printf. ... Yes. A space, 4 digits for
the year, 2 for the month, 2 for the day. So this will do:
printf FILE " %04d%02d%02d", $year, $month, $day;
>#String 1 date & time stamp and report name
>#Basically fills in a leading ")" for minutes and hours less than 10
>if ($min >= 10 && $hour >= 10) {
> print FILE ($hour);
> print FILE ":",($min)," AMBATCH REPORT (OLD)
>";
> } elsif ($min <= 9 && $hour >= 10) {
> print FILE ($hour);
> print FILE ":","0",($min)," AMBATCH REPORT (OLD)
>";
> } elsif ($min >= 10 && $hour <= 9) {
> print FILE "0",($hour);
> print FILE ":",($min)," AMBATCH REPORT (OLD)
>";
> } elsif ($min >= 10 && $hour <= 9) {
> print FILE "0",($hour);
> print FILE ":","0",($min)," AMBATCH REPORT (OLD)
>";
> }
>}
Same kind of shit. You want
printf "%02d:%02d%s", $hour, $min, " AMBATCH REPORT (OLD)\n";
but you can combine this with the other printf:
printf " %04d%02d%02d%02d:%02d%s", $year, $month, $day,
$hour, $min, " AMBATCH REPORT (OLD)\n";
You could embed you "AMBATCH..." string in your printf format, instead
of the "%s".
--
Bart.
------------------------------
Date: Fri, 02 Feb 2001 11:09:45 GMT
From: Andre Bonhote <andre.bonhote@linux.ch>
Subject: getting file permissions and owner on ufs
Message-Id: <3A7A9564.926FB017@linux.ch>
hi group!
i have one quite tricky question to ask (at least for me). hope you can
answer it.
when i have files, like say /etc/passwd, /etc/shadow, how can i get its
permissions in octal form (0666), its group and its owner? i know two
really platform dependant ways to do so:
1. have something like @ls=3D`ls -l *whateverilike*` and split all the
lines into pieces. then check for each character, if it's r, x, d,
whatever, and build my own octal number out of it. annoying and ugly.
2. perform filetests for each case. dunno how to get the user/group
thing done though. ugly as well.
perl is so powerful and well-known allover the world, therefore i guess
i am not the only one looking for a solution of this problem. i really
beleive that, somewhere out there, there is a module or something doing
this. like $user=3Duser($filename) and so on.
thank you for your kind help
yours
andr=E9
------------------------------
Date: 2 Feb 2001 11:37:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: getting file permissions and owner on ufs
Message-Id: <95e65j$l3o$1@mamenchi.zrz.TU-Berlin.DE>
Andre Bonhote <andre.bonhote@linux.ch> wrote in comp.lang.perl.misc:
>hi group!
>
>i have one quite tricky question to ask (at least for me). hope you can
>answer it.
>
>when i have files, like say /etc/passwd, /etc/shadow, how can i get its
>permissions in octal form (0666), its group and its owner? i know two
>really platform dependant ways to do so:
>
>1. have something like @ls=`ls -l *whateverilike*` and split all the
>lines into pieces. then check for each character, if it's r, x, d,
>whatever, and build my own octal number out of it. annoying and ugly.
>2. perform filetests for each case. dunno how to get the user/group
>thing done though. ugly as well.
>
>perl is so powerful and well-known allover the world, therefore i guess
>i am not the only one looking for a solution of this problem. i really
>beleive that, somewhere out there, there is a module or something doing
>this. like $user=user($filename) and so on.
Look up the stat() function in perldoc.
In particular, "$mode = ( stat $file)[ 2]" sets $mode to a numeric
value that encodes the file permissions and the file type. The
permissions are the 12 least significant bits of that number, so
$perm = $mode & 07777 isolates the permissions.
Note that this is a numeric value; to see the accustomed representation
in octal use (s)printf with the "o" format specifier.
Anno
------------------------------
Date: Fri, 02 Feb 2001 11:45:56 GMT
From: Andre Bonhote <andre.bonhote@linux.ch>
Subject: Re: getting file permissions and owner on ufs
Message-Id: <3A7A9DDE.55ACB82@linux.ch>
> Look up the stat() function in perldoc.
> =
> In particular, "$mode =3D ( stat $file)[ 2]" sets $mode to a numeric
> value that encodes the file permissions and the file type. The
> permissions are the 12 least significant bits of that number, so
> $perm =3D $mode & 07777 isolates the permissions.
> =
> Note that this is a numeric value; to see the accustomed representation=
> in octal use (s)printf with the "o" format specifier.
> =
> Anno
thank you! thats great! in the meantime i found the File::stat module
which is obviously doing sth similar. i'm not that good at AND/OR, so
i'm glad you helped me. thanks a lot!
yours
andr=E9
------------------------------
Date: Fri, 2 Feb 2001 13:35:39 +0000
From: matt@cipherdesign.com (Matt Venn)
Subject: Re: Handling Errors nicely
Message-Id: <slrn97ldtb.as7.matt@flop.localnet>
Thanks for all the help.
Matt
--
#!/usr/bin/perl
$A='A';while(print+($A.=(grep{($A=~/(...).{78}$/)[0]eq$_}" A A A "
=~m{(...)}g)?"A":" ")=~/([ A])$/){if(!(++$l%80)){print"\n";sleep 1}}
------------------------------
Date: 2 Feb 2001 12:32:59 GMT
From: Bernhard Brueck <news@brueck.muc.de>
Subject: Re: Linux does reclaim memory from perl
Message-Id: <95e9dr$2ii$1@brueck.local>
Jerome Abela <Jerome.Abela@free.fr> wrote:
> Joe Schaefer wrote :
>> I think the keyword here is "may". I get similar results on linux with
>> bit vectors (it frees everything), but scalars aren't so fortunate:
>>
>> $a = "XYZ" x 1000000;
>>
>> joe 8453 2.0 1.7 2624 1088 pts/1 perl -wl ./try.pl
>> joe 8453 12.0 7.9 6536 5008 pts/1 perl -wl ./try.pl
>> joe 8453 4.0 4.8 4580 3056 pts/1 perl -wl ./try.pl
> I could observe similar results. I think "XYZ" x 1000000 allocates a
> first memory chunk, which is in turn copied into another one for $a.
> That's why my examlple used vec(): no string affectation, no double
> allocation.
>> > Is it related to some recent changes in perl ? The 'yet' may imply that
>> > someone was working on it at the time this item of the FAQ was written ?
>>
>> I think it's more related to how the memory was originally allocated;
> Yes, sure. The main difficulty to release memory to the OS, is that you
> can only release memory at the end of your memory space, so you need to
> be able to move objects around to make it happen.
That depends on the internals of the malloc routines beeing used.
When malloc uses solely sbrk calls to get memory from the OS then only
memory space at the end of the data segment can be released.
GNU malloc uses a threshold (default 128k) to decide weather sbrk or mmap
should be used. Therefore its possible to return memory to the OS when
a chunk of more then 128k was allocated all at once.
Bernhard
--
-----------------------------------------------------------------------------
Dipl.-Inform. Univ. Bernhard Brueck email: news@brueck.muc.de
------------------------------
Date: 2 Feb 2001 11:58:45 GMT
From: jab@realprogrammer.com (jay)
Subject: matching integer's and end of a string problem
Message-Id: <903C73381jabrealprogrammercom@158.43.128.9>
Hi All,
I am trying to test to see if a scalar is an integer or not. Now the
FAQ suggests:
if (/^-?\d+$/) { print "is an integer\n" }
which looked good so I tried it.
#!usr/bin/perl -w
use strict;
while (<DATA>) {
# chomp;
print "[$_] is ", is_integer($_) ? '' : 'not ', "an integer\n";
}
sub is_integer {
$_[0] =~ /^\-?\d$/ ? 1 : 0
}
__DATA__
hello
2
1
0
-1
-2
the result was:
[hello
] is not an integer
[2
] is an integer
[1
] is an integer
[0
] is an integer
[-1
] is an integer
[-2
] is an integer
now my problem is that I don't want the pattern to match if there is a
carage return or line feed at the end of the scalar (as there obviously
is).
It suggests in the Programming Perl book (2nd edition) to use an s
modifier for the pattern match if you want to :
"Treat string as single line (^ and $ ignore \n, but . matches \n)"
but this does not seem to be the case for the end of string.
Any ideas what am I missing?
Thanks for any help.
------------------------------
Date: Fri, 2 Feb 2001 12:43:39 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: matching integer's and end of a string problem
Message-Id: <slrn97larp.2q0.bernard.el-hagin@gdndev25.lido-tech>
On 2 Feb 2001 11:58:45 GMT, jay <jab@realprogrammer.com> wrote:
>Hi All,
>
>I am trying to test to see if a scalar is an integer or not. Now the
>FAQ suggests:
>
> if (/^-?\d+$/) { print "is an integer\n" }
>
>which looked good so I tried it.
>
>#!usr/bin/perl -w
>use strict;
>
>while (<DATA>) {
># chomp;
> print "[$_] is ", is_integer($_) ? '' : 'not ', "an integer\n";
>}
>
>sub is_integer {
> $_[0] =~ /^\-?\d$/ ? 1 : 0
>}
>
>__DATA__
>hello
>2
>1
>0
>-1
>-2
[snipped results]
>now my problem is that I don't want the pattern to match if there is a
>carage return or line feed at the end of the scalar (as there obviously
>is).
How about changing the regex to:
$_[0] =~ /^\-?\d$(?!\n)/;
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Fri, 02 Feb 2001 12:48:28 +0000
From: Tom Scheper <tom@power.net.uk>
Subject: Re: matching integer's and end of a string problem
Message-Id: <42bl7t8ifptdko567jjuitclbdhq8la7en@4ax.com>
Hi Jay,
I've added a + to your \d so it can match integers of several digits.
I couldn't easily find a way to include a \n match in the regular
expression, but used chomp instead to determine an eol character.
This worked for me, but I don't know if it's sufficient for you.
-=Cornelis
#!/usr/bin/perl -w
use strict;
while (<DATA>) {
# chomp;
print "[$_] is ", is_integer($_) ? '' : 'not ', "an integer\n";
}
sub is_integer {
chomp $_[0] ? 0 : $_[0] =~ /^\-?[\d]+$/ ? 1 : 0
}
__DATA__
hello
2
1
0
-1
-2
On 2 Feb 2001 11:58:45 GMT, jab@realprogrammer.com (jay) shed a beam
of light on us:
>Hi All,
>
>I am trying to test to see if a scalar is an integer or not. Now the
>FAQ suggests:
>
> if (/^-?\d+$/) { print "is an integer\n" }
>
>which looked good so I tried it.
>
>#!usr/bin/perl -w
>use strict;
>
>while (<DATA>) {
># chomp;
> print "[$_] is ", is_integer($_) ? '' : 'not ', "an integer\n";
>}
>
>sub is_integer {
> $_[0] =~ /^\-?\d$/ ? 1 : 0
>}
>
>__DATA__
>hello
>2
>1
>0
>-1
>-2
>
>the result was:
>
>[hello
>] is not an integer
>[2
>] is an integer
>[1
>] is an integer
>[0
>] is an integer
>[-1
>] is an integer
>[-2
>] is an integer
>
>now my problem is that I don't want the pattern to match if there is a
>carage return or line feed at the end of the scalar (as there obviously
>is).
>
>It suggests in the Programming Perl book (2nd edition) to use an s
>modifier for the pattern match if you want to :
>
>"Treat string as single line (^ and $ ignore \n, but . matches \n)"
>
>but this does not seem to be the case for the end of string.
>
>Any ideas what am I missing?
>
>Thanks for any help.
------------------------------
Date: 2 Feb 2001 12:51:20 GMT
From: abigail@foad.org (Abigail)
Subject: Re: matching integer's and end of a string problem
Message-Id: <slrn97lba8.udn.abigail@tsathoggua.rlyeh.net>
Bernard El-Hagin (bernard.el-hagin@lido-tech.net) wrote on MMDCCXII
September MCMXCIII in <URL:news:slrn97larp.2q0.bernard.el-hagin@gdndev25.lido-tech>:
() On 2 Feb 2001 11:58:45 GMT, jay <jab@realprogrammer.com> wrote:
()
() >now my problem is that I don't want the pattern to match if there is a
() >carage return or line feed at the end of the scalar (as there obviously
() >is).
()
() How about changing the regex to:
()
() $_[0] =~ /^\-?\d$(?!\n)/;
How about just RTFM and use the appropriate zero-width assertion?
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Fri, 2 Feb 2001 12:55:14 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: matching integer's and end of a string problem
Message-Id: <slrn97lbh7.2q0.bernard.el-hagin@gdndev25.lido-tech>
On 2 Feb 2001 12:51:20 GMT, Abigail <abigail@foad.org> wrote:
>Bernard El-Hagin (bernard.el-hagin@lido-tech.net) wrote on MMDCCXII
>September MCMXCIII in <URL:news:slrn97larp.2q0.bernard.el-hagin@gdndev25.lido-tech>:
>() On 2 Feb 2001 11:58:45 GMT, jay <jab@realprogrammer.com> wrote:
>()
>() >now my problem is that I don't want the pattern to match if there is a
>() >carage return or line feed at the end of the scalar (as there obviously
>() >is).
>()
>() How about changing the regex to:
>()
>() $_[0] =~ /^\-?\d$(?!\n)/;
>
>
>How about just RTFM and use the appropriate zero-width assertion?
TMTWWTDI.
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: 2 Feb 2001 13:03:01 GMT
From: jay@N_OSPAMcastlelink.co.uk (Jay Bowers)
Subject: Re: matching integer's and end of a string problem
Message-Id: <903C82212jabrealprogrammercom@158.43.128.9>
bernard.el-hagin@lido-tech.net (Bernard El-Hagin) wrote in
<slrn97larp.2q0.bernard.el-hagin@gdndev25.lido-tech>:
>On 2 Feb 2001 11:58:45 GMT, jay <jab@realprogrammer.com> wrote:
>>Hi All,
>>
>>I am trying to test to see if a scalar is an integer or not. Now
>>the FAQ suggests:
>>
>> if (/^-?\d+$/) { print "is an integer\n" }
>>
>>which looked good so I tried it.
>>
>>#!usr/bin/perl -w
>>use strict;
>>
>>while (<DATA>) {
>># chomp;
>> print "[$_] is ", is_integer($_) ? '' : 'not ', "an integer\n";
>>}
>>
>>sub is_integer {
>> $_[0] =~ /^\-?\d$/ ? 1 : 0
>>}
>>
>>__DATA__
>>hello
>>2
>>1
>>0
>>-1
>>-2
>
>[snipped results]
>
>>now my problem is that I don't want the pattern to match if there
>>is a carage return or line feed at the end of the scalar (as there
>>obviously is).
>
>How about changing the regex to:
>
>$_[0] =~ /^\-?\d$(?!\n)/;
>
Hummm.... works. Looks like I'll have to read the manual a bit more and
see if I can find out why.
Thanks,
Jay.
------------------------------
Date: 02 Feb 2001 13:06:43 +0000
From: nobull@mail.com
Subject: Re: matching integer's and end of a string problem
Message-Id: <u9d7d1fd3w.fsf@wcl-l.bham.ac.uk>
jab@realprogrammer.com (jay) writes:
> Subject: matching integer's and end of a string problem
Always try to reduce your problem to its simplest form.
You've solved the matching integers bit so your questions is: What can
I put in a Perl regex that will match the absolute end of the string
and not just before the terminal \n?
Or as a subject line:
Subject: RE to match absolute end of string
Of course once you've reduced the problem to its simplest form the
answer should jump out at you when you look in "perldoc perlre".
> if (/^-?\d+$/) { print "is an integer\n" }
>
> which looked good so I tried it.
> now my problem is that I don't want the pattern to match if there is a
> carage return or line feed at the end of the scalar (as there obviously
> is).
if (/^-?\d+\z/) { print "is an integer\n" }
> It suggests in the Programming Perl book (2nd edition) to use an s
> modifier for the pattern match if you want to :
>
> "Treat string as single line (^ and $ ignore \n, but . matches \n)"
>
> but this does not seem to be the case for the end of string.
That is correct. "ignore \n" should, pedantically speaking, read
"ignore embeded \n"
The paragraph in "perldoc perlre" tells the true situation:
s Treat string as single line. That is, change "." to
match any character whatsoever, even a newline, which
it normally would not match.
The /s and /m modifiers both override the $* setting.
That is, no matter what $* contains, /s without /m
will force "^" to match only at the beginning of the
string and "$" to match only at the end (or just
before a newline at the end) of the string. Together,
as /ms, they let the "." match any character
whatsoever, while yet allowing "^" and "$" to match,
respectively, just after and just before newlines
within the string.
So even with /s "$" will match just before a newline at the end of the
string.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 02 Feb 2001 13:19:42 GMT
From: mexicanmeatballs@my-deja.com
Subject: Re: matching integer's and end of a string problem
Message-Id: <95ec59$r0t$1@nnrp1.deja.com>
In article <903C73381jabrealprogrammercom@158.43.128.9>,
jab@realprogrammer.com (jay) wrote:
> now my problem is that I don't want the pattern to match if there is a
> carage return or line feed at the end of the scalar (as there
obviously
> is).
sub is_integer {
$_[0] =~ /^\-?\d\z/ ? 1 : 0
}
perldoc perlre
<snip>
Perl defines the following zero-width assertions:
<snip>
\z Match only at end of string
--
Jon
perl -e '$|=($_)=(pop);A:$_=~s/.(.)(.*)/\r$2$1/;print;
select pop,pop,pop,.10;goto A' ' iname.com JonBarker@'
--
Jon
perl -e '$|=($_)=(pop);A:$_=~s/.(.)(.*)/\r$2$1/;print;
select pop,pop,pop,.10;goto A' ' iname.com JonBarker@'
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 2 Feb 2001 11:58:53 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Opera Hotlist To HTML
Message-Id: <slrn97l87t.udn.abigail@tsathoggua.rlyeh.net>
Daniel Loose (daniel42@web.de) wrote on MMDCCXII September MCMXCIII in
<URL:news:3A7A8FCD.F60F0FBD@web.de>:
\\ Hello,
\\
\\ I want to write a little script which converts the opera hotlist file
\\ (.adr, I think) to HTML. (So that I can put my bookmarks on the net and
\\ surf from other places.) But I could not figure out how opera
\\ reconstructs the tree structure of the bookmark folders from the .adr
\\ file. Does anyone here know that?
\\ Sorry if you think that's OT but my hope is that any perl programmer
\\ here has already written such a tool and therefore solved the problem.
It's still off topic. You're asking for a canned solution - and hence
it's irrelevant whether it's written in Perl or some other language.
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: 02 Feb 2001 12:34:44 +0000
From: nobull@mail.com
Subject: Re: Possible buggy behavior in File::Find
Message-Id: <u9g0hxfel7.fsf@wcl-l.bham.ac.uk>
ben-fuzzybear@geocities.com (Ben Okopnik) writes:
> Subject: Re: Possible buggy behavior in File::Find
From perldoc File::Find:
File::Find assumes that you don't alter the $_ variable.
If you do then make sure you return it to its original
value before exiting your function.
Note: it doesn't mention that File::Find also assumes that you don't
change the CWD.
> #**** Here is the problem! ****
> while (<Mod>) {
Correct, the above modifies $_.
Insert "local $_;" before the above loop.
> foreach $found (<Mod>) {
> This one generates no errors.
Because it doesn't modify $_.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 2 Feb 2001 12:37:04 -0000
From: "Robert Morrissey" <robert@NOSPAMcrazymoose.co.uk>
Subject: regexp
Message-Id: <LQxe6.1$yf2.851@news.dircon.co.uk>
Hi,
I'm looking for a way to match something 'unless' it occurs in a certain
way, I'll give an example as this isn't clear:
I have (say) a string that is "mp3s/01-perl-is-great.mp3" and want to rename
it as "mp3s/01-perlisgreat.mp3", so I am looking for a way to say replace
all "-" with "" unless "-" occurs after a forward slash and two digits. I'm
not asking for a regular expression obviously, this was just an example --
but rather I am banging my head against the wall for a way to incorporate an
'unless' into a regexp -- is this possible?
Thanks in advance,
Robert Morrissey
------------------------------
Date: 2 Feb 2001 12:52:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regexp
Message-Id: <95eahh$o99$1@mamenchi.zrz.TU-Berlin.DE>
Robert Morrissey <robert@NOSPAMcrazymoose.co.uk> wrote in comp.lang.perl.misc:
>Hi,
> I'm looking for a way to match something 'unless' it occurs in a certain
>way, I'll give an example as this isn't clear:
>
>I have (say) a string that is "mp3s/01-perl-is-great.mp3" and want to rename
>it as "mp3s/01-perlisgreat.mp3", so I am looking for a way to say replace
>all "-" with "" unless "-" occurs after a forward slash and two digits. I'm
>not asking for a regular expression obviously, this was just an example --
>but rather I am banging my head against the wall for a way to incorporate an
>'unless' into a regexp -- is this possible?
Look for the words "lookahead" and "lookbehind" in perlre. That may be
what you are looking for.
Anno
------------------------------
Date: 2 Feb 2001 12:00:38 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Sting validation question...?
Message-Id: <slrn97l8b6.udn.abigail@tsathoggua.rlyeh.net>
pkey@sghms.ac.uk (pkey@sghms.ac.uk) wrote on MMDCCXII September MCMXCIII
in <URL:news:bq1l7ts8bvrk6iqjtl3309nsu3p261ih12@4ax.com>:
:: What regular expression do I need to use to validate that a string
:: contains at least one integer i.e. it is not made up just of the 26
:: letters of the alphabet and that it is not just made up of numbers
:: alone?
Your two wordings of your request don't match. "&(&" is not made up
of the 26 characters but doesn't contain an integer. It isn't made up
of numbers alone either.
Please state your problem correctly - that's 95% of solving the problem
anyway.
Abigail
--
perl -wle 'eval {die ["Just another Perl Hacker"]}; print ${$@}[$#{@${@}}]'
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 199
**************************************