[24083] in Perl-Users-Digest
Perl-Users Digest, Issue: 6277 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 19 09:05:45 2004
Date: Fri, 19 Mar 2004 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)
Perl-Users Digest Fri, 19 Mar 2004 Volume: 10 Number: 6277
Today's topics:
Re: Can somebody please help me <tore@aursand.no>
Re: converting an evaluated expression to a literal (Anno Siegel)
dollar sign and spaces from a string <bill@hotmail.com>
Re: dollar sign and spaces from a string (Anno Siegel)
Re: dollar sign and spaces from a string <jurgenex@hotmail.com>
Re: dollar sign and spaces from a string <jurgenex@hotmail.com>
Re: dollar sign and spaces from a string (another one)
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Re: FIFO problem - yet another .sig rot script... <krahnj@acm.org>
Re: FIFO problem - yet another .sig rot script... <bik.mido@tiscalinet.it>
Re: get filename using regexp and if <krahnj@acm.org>
Re: get filename using regexp and if <PerlGuRu2b@bobotheclown.org>
Re: HOW TO PARSE A VAST FILE! <mb@uq.net.au.invalid>
How to reset a POP3 session <spam-block-@-SEE-MY-SIG.com>
Re: NET::FTP debug output <mail@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 19 Mar 2004 11:26:50 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Can somebody please help me
Message-Id: <pan.2004.03.19.10.17.13.423724@aursand.no>
On Fri, 19 Mar 2004 00:32:56 +0000, Jill wrote:
> How can I read the variable that is passed to a url like
> www.mydomain.com/test.html?SVAR=55
> I want to access the SVAR variable and store it in the cookie, then
> retrieve it later again to display if this person revisits site.
perldoc CGI
> how to I modify
> http://javascript.internet.com/cookies/id-tracker.html to make it work.
Javascript != Perl
--
Tore Aursand <tore@aursand.no>
"Fighting terrorism is like being a goalkeeper. You can make a hundred
brilliant saves but the only shot that people remember is the one that
gets past you." -- Paul Wilkinson
------------------------------
Date: 19 Mar 2004 10:35:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: converting an evaluated expression to a literal
Message-Id: <c3eiee$hf6$1@mamenchi.zrz.TU-Berlin.DE>
Paul Lalli <ittyspam@yahoo.com> wrote in comp.lang.perl.misc:
> On Thu, 18 Mar 2004, Ashkan wrote:
>
> > Hi,
> >
> > I'm performing pattern substitution and I'm having some problems when
> > my pattern contains the following structure: "[3]".
> >
> > Here is a snippet of my code:
> >
> > while ($count ne 0) {
> > $file[$count] =~ s#$value[$val_count]#sub[$val_count]#g;
> > $count--;
> > }
> > Is there any way for the $value[$val_count] to be evaluated, then the
> > output be treated as a literal?
>
> s/\Q$value[$val_count]\E/sub[$val_count]/g;
>
> the \Q ... \E syntax escapes (backslashes) all 'special' characters in the
> string, rendering [ and ] as plain old brackets, so they no longer have
> their special meaning in a regexp.
Did you test that? If it worked that way, \Q would also quote "$",
so no interpolation would happen at all.
Variable interpolation happens before \Q is applied. If it didn't,
the main application of \Q to protect metacharacters in interpolated
strings wouldn't work.
To have "$value" in "$value[$val_count]" to be interpreted as a scalar
variable, you need explicit backslashes before the brackets:
s/$value\[$val_count\]/sub[$val_count]/g;
Depending on the content of $value and $val_count, \Q may also be
needed.
Anno
------------------------------
Date: Fri, 19 Mar 2004 13:07:58 GMT
From: "Bill" <bill@hotmail.com>
Subject: dollar sign and spaces from a string
Message-Id: <OgC6c.27994$E8.6370776@news4.srv.hcvlny.cv.net>
Hi
How can I remove the dollar sign and spaces from a string and keep the +?
This dont work
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$weight = "8.5 + $10.00";
$weight =~ s/ \$//g;
print "$weight";
------------------------------
Date: 19 Mar 2004 13:20:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: dollar sign and spaces from a string
Message-Id: <c3es29$q27$1@mamenchi.zrz.TU-Berlin.DE>
Bill <bill@hotmail.com> wrote in comp.lang.perl.misc:
> Hi
>
> How can I remove the dollar sign and spaces from a string and keep the +?
>
> This dont work
>
> #!/usr/bin/perl
>
> print "Content-type: text/html\n\n";
>
> $weight = "8.5 + $10.00";
> $weight =~ s/ \$//g;
>
> print "$weight";
$weight =~ tr/ $//d;
Anno
------------------------------
Date: Fri, 19 Mar 2004 13:24:51 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: dollar sign and spaces from a string
Message-Id: <DwC6c.46723$F9.40952@nwrddc01.gnilink.net>
Bill wrote:
> How can I remove the dollar sign and spaces from a string and keep
> the +?
>
> This dont work
>
> #!/usr/bin/perl
You are missing
use strict;
use warnings;
> print "Content-type: text/html\n\n";
What does this line have to do with your problem? It just produces spurious
output.
> $weight = "8.5 + $10.00";
If you would have used warnings then perl would have told you that the
variable $10 is not defined/initialized. Maybe you meant
my $weight = '8.5 + $10.00';
instead?
> $weight =~ s/ \$//g;
Nothing wrong with the substitute command.
jue
------------------------------
Date: Fri, 19 Mar 2004 13:27:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: dollar sign and spaces from a string
Message-Id: <9zC6c.46724$F9.8836@nwrddc01.gnilink.net>
Anno Siegel wrote:
> Bill <bill@hotmail.com> wrote in comp.lang.perl.misc:
[...]
>> $weight = "8.5 + $10.00";
>> $weight =~ s/ \$//g;
>>
>> print "$weight";
>
> $weight =~ tr/ $//d;
Nice idea, but won't solve his problem. His original string doesn't contain
a dollar sign to begin with.
jue
------------------------------
Date: Fri, 19 Mar 2004 13:34:12 +0000
From: "Steve (another one)" <y66y@56yu4b6.com>
Subject: Re: dollar sign and spaces from a string
Message-Id: <c3essk$h1q$1@news.liv.ac.uk>
Jürgen Exner wrote:
> Bill wrote:
>
>>How can I remove the dollar sign and spaces from a string and keep
>>the +?
>>
>>This dont work
>>
>>#!/usr/bin/perl
>
>
> You are missing
> use strict;
> use warnings;
>
>
>>print "Content-type: text/html\n\n";
>
>
> What does this line have to do with your problem? It just produces spurious
> output.
>
>
>>$weight = "8.5 + $10.00";
>
>
> If you would have used warnings then perl would have told you that the
> variable $10 is not defined/initialized. Maybe you meant
> my $weight = '8.5 + $10.00';
> instead?
>
>
>>$weight =~ s/ \$//g;
>
>
> Nothing wrong with the substitute command.
>
> jue
>
>
And when you found it didn't work, you could have tested your feeling
that the problem was in the subsitute by printing the string before and
after you s'd it. You would have found there never was a $ to remove.
Quicker than asking the world and you wouldn't have had to put-up with
all these smart comments!
------------------------------
Date: 19 Mar 2004 09:36:22 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1079688903@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
XEmacs port is bundled in XEmacs setup.exe available from
XEmacs site.
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
<ilya@math.ohio-state.edu> Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr@ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Fri, 19 Mar 2004 09:32:44 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: FIFO problem - yet another .sig rot script...
Message-Id: <405ABE29.36E4083D@acm.org>
Michele Dondi wrote:
>
> <intro>
> I'm trying to write a .sig rotation script for client-independet use
> by means of a FIFO. This attempt is also and (possibly even) *mainly*
> for learning purposes: the fact that I'm encountering the difficulties
> described hereafter shows that indeed it is well suited for that...
> </intro>
>
> Well, to make a long story brief, I adatped code and suggestions from
> 'perldoc perlipc' and 'perldoc -q daemon' to conjure up a script
> (pasted below with non-significative portions commented out) that
> actually works well with e.g.
>
> cat .signature
>
> or
>
> perl -lpe "" .signature
>
> But when I try it with pine when composing a mail, the process started
> by my script dies and .sig is not inserted!
Some mail programs won't use a FIFO .sig file. Perhaps pine is one of
them?
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 19 Mar 2004 14:54:05 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FIFO problem - yet another .sig rot script...
Message-Id: <3ptl5018889hcgkhml62auqe82ppmvtkl9@4ax.com>
On Fri, 19 Mar 2004 09:32:44 GMT, "John W. Krahn" <krahnj@acm.org>
wrote:
>> But when I try it with pine when composing a mail, the process started
>> by my script dies and .sig is not inserted!
>
>Some mail programs won't use a FIFO .sig file. Perhaps pine is one of
>them?
Appearently it may well be so... BUT! then it is reasonable to suppose
that in that case it would silently refuse to open it for reading
*and* leave my process alone instead of (inadvertently, I hope ;-)
killing it.
Also, it *seems* that .signature is not checked to be a regular file,
since a symlink works too, but of course it may explicitly check that
it is *not* a FIFO, even if I can't understand why the hell it
should!!
I even tried a mid-hearted attempt at using a symlink to the actual
FIFO as the .sig file, but it fails quite as miserably...
Wild guess: isn't it that pine is trying to open() it in read/write
mode or to lock it or WTF I know what?!? And as far as the Perl-OT
content of this post is concerned: can anybody with some experience in
*NIX programming give me some suggestions about how to use e.g. strace
or similar tools to find out what pine is doing?!?
TIA,
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Fri, 19 Mar 2004 11:47:16 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: get filename using regexp and if
Message-Id: <405ADDB1.68142310@acm.org>
Rocky wrote:
>
> I have a small issue:
> here is code that I wrote (please don't make fun of it as I am a newbie)
> to get the highest numbered backuplog from a veritas server via ftp:
> @filenums = 0;
You are assigning 0 to the first element of @filenums which doesn't make
sense. If you want to ensure that @filenums is empty you should assign
the empty list or use my().
@filenums = ();
> foreach $file (@files) {
> if ($file =~ m/([A-Za-z]{2}X)(\d+)(\.txt)/) {
> push(@letter, $1);
> push(@filenums, $2);
> push(@ext, $3);
> $ext = pop(@ext);
> }
> if ($file =~ m/([A-Za-z]{2}X)(\d+)(\.xml)/) {
> push(@letter, $1);
> push(@filenums, $2);
> push(@ext, $3);
> $ext = pop(@ext);
> }
You have two if blocks but almost all the code in both is identical so
you could combine them into one if block. Your regular expressions are
not anchored so you may be matching invalid file names.
> }
> $letters = pop(@letter);
> $highest = (sort { $a <=> $b } @filenums)[-1];
$letters and $ext are from the last file in @files but $highest is not
necessarily from the same file. There is no need to use three arrays
when all you need is one file name.
my $ftp_file = [ '', 0 ];
foreach my $file ( @files ) {
if ( $file =~ /^[A-Za-z]{2}X(\d+)\.(?:txt|xml)$/ ) {
$ftp_file = [ $file, $1 ] if $ftp_file->[ 1 ] < $1;
}
}
$ftp->get( $ftp_file->[ 0 ] ) or print ...
> $ftp->get($letters . $highest . $ext) or print FILENAMES $letters . $highest . $ext . "\n";
>
> Please note the last line which prints to a file if it cannot get the file
> it wants. I updated the script to get any file modified in the last 24
> hours and bearing the extension .txt or .xml (necessary since some of the
> servers have two jobs per night)
> here is the new code:
>
> $rightnow = time();
> [snip]
>
> @filenames = $ftp->ls;
> foreach $file (@filenames) {
> $time = $ftp->mdtm($file);
> $goodfile = $rightnow - $time;
> $ftp->get($file) if ($goodfile < "86400" & $file =~ /.*\.txt|.*\.xml/);
It looks like you are assuming that the time on your machine and the
time on the FTP server are synchronised. Is this assumption correct?
You are telling perl to convert the string "86400" to a number to
compare it to $goodfile when you could just use the number 86400
instead. You are using the bit-wise & operator when you probably meant
to use && or 'and'. Your regular expression isn't anchored so it may
match invalid files.
> the problem:
> whenever I add "or print FILENAMES ..." to the last line it gets every file in
> the remote dir.
Where in the line do you add it?
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 19 Mar 2004 13:24:35 GMT
From: Rocky <PerlGuRu2b@bobotheclown.org>
Subject: Re: get filename using regexp and if
Message-Id: <pan.2004.03.19.13.29.02.85894@bobotheclown.org>
On Thu, 18 Mar 2004 18:48:33 -0500, Matt Garrish wrote:
Hey Matt. That worked ... you rock.
Rocky
>
> "Rocky" <PerlGuRu2b@bobotheclown.org> wrote in message
> news:pan.2004.03.18.21.41.32.413018@bobotheclown.org...
>>
>> $ftp->get($file) if ($goodfile < "86400" & $file =~ /.*\.txt|.*\.xml/);
>>
>> the problem:
>> whenever I add "or print FILENAMES ..." to the last line it gets every
> file in
>> the remote dir.
>
>
> Most likely because there are a whole slew of problems with the above code.
> Going on the assumption that you typed that code in, the or is interpreted
> as being part of the if statement (i.e. get the file if the expressions in
> parens match, OR if the filename can be printed). One line statements are
> all the rage, but sometimes you can try and do too much in them:
>
> if (($goodfile < 86400) && ($file =~ /.*\.txt|.*\.xml/)) {
> $ftp->get($file)
> }
> else {
> print $file, "\n";
> }
>
> Matt
------------------------------
Date: Fri, 19 Mar 2004 17:02:20 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: HOW TO PARSE A VAST FILE!
Message-Id: <c3e5ts$3sg$1@bunyip.cc.uq.edu.au>
Tore Aursand wrote:
<snip>
> my %ip_addresses;
> while ( <DATA> ) {
> if ( /^(.*?)\s+/ ) {
> $ip_addresses{$1}++;
> }
> }
>
> my $stInsert = $dbh->prepare( 'INSERT INTO ip_addresses (ip_address) VALUES (?)' );
> foreach ( keys %ip_addresses ) {
> $stInsert->execute( $_ );
> }
> $stInsert->finish();
>
>
If its mysql, you probably want INSERT IGNORE, instead of INSERT. Might be
faster since it suddenly doesn't care about generating errors on duplicate keys.
Of course, this depends on your version of mysql.
You could also do it in batches, but you'd have to be careful about the last
batch in case it doesn't have enough members for your ?'s, eg
my %ip_addresses;
while ( <DATA> ) {
if ( /^(.*?)\s+/ ) {
$ip_addresses{$1}++;
}
}
my $ctstep = 100;
my $stInsert =
($dbh->prepare('INSERT IGNORE INTO ip_addresses (ip_address) VALUES ' .
join(", ", '(?)' x $ctstep)));
my $ct = 0;
my @addresses = keys %ip_addresses;
while ($ct * $ctstep < scalar(@addresses)) {
my @range = @addresses[($ct * $ctstep)..((($ct + 1) * $ctstep) - 1)];
if (scalar(@range) == $ctstep) {
$stInsert->execute(@range);
} else {
# Last group is too short - change the query
$stInsert =
($dbh->prepare('INSERT IGNORE INTO ip_addresses (ip_address) VALUES '.
join(", ", '(?)' x scalar(@range))));
$stInsert->execute(@range);
last;
# You could also expand @range and let the IGNORE take effect instead
# of rebuilding the query, ie
# @range[(scalar(@range) - 1)..99] =
# $range[scalar(@range) - 1] x (100 - scalar(@range));
# $stInsert->execute(@range);
# last;
}
++$ct;
}
$stInsert->finish;
------------------------------
Date: Fri, 19 Mar 2004 13:06:05 +0000
From: James Taylor <spam-block-@-SEE-MY-SIG.com>
Subject: How to reset a POP3 session
Message-Id: <ant1913051cbfNdQ@nospam.demon.co.uk>
Hi guys,
I'm using the Net::POP3 module and would like to know how to use its
reset() method properly. There ought to be a way to issue the POP3
RESET command and know whether it succeeded, but I can't see how.
Has anyone else managed to use the Net::POP3 module for this?
Please advise me if you can; I'm very stuck. Thanks.
PS. You might find further background to the problem over here:
http://groups.google.com/groups?th=1ed4ebecbab686f7
--
James Taylor, Cheltenham, Gloucestershire, UK. PGP key: 3FBE1BF9
To protect against spam, the address in the "From:" header is not valid.
In any case, you should reply to the group so that everyone can benefit.
If you must send me a private email, use james at oakseed demon co uk.
------------------------------
Date: Fri, 19 Mar 2004 09:03:44 -0000
From: "bob" <mail@mail.com>
Subject: Re: NET::FTP debug output
Message-Id: <vr2cnfw7e-ZdKsfdSa8jmw@karoo.co.uk>
its changing to a directory but the directory is not valid in some way.
"mike" <s99999999s2003@yahoo.com> wrote in message
news:dfd17ef4.0403182028.3170dd39@posting.google.com...
> hi
> when i use NET::FTP to get some files from an ftp server, i get this
message
>
> Net::FTP=GLOB(0x1c98f4c)>>> CWD /
> Net::FTP=GLOB(0x1c98f4c)<<< 501 A qualifier in "/" begins with an invalid
cha
> cter
>
> What does this error mean?
> thanks
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6277
***************************************