[18266] in Perl-Users-Digest
Perl-Users Digest, Issue: 434 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 7 09:10:37 2001
Date: Wed, 7 Mar 2001 06:10:19 -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: <983974218-v10-i434@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 7 Mar 2001 Volume: 10 Number: 434
Today's topics:
Re: Newbie: How do I count something in a file <krahnj@acm.org>
Re: Newbie: How do I count something in a file <bart.lateur@skynet.be>
Re: Newbie: How do I count something in a file (Philip Lees)
Re: Newbie: How do I count something in a file (Monte)
Re: perl editors (Harri Haataja)
Re: Perl fortune database - where? (was: Dynamic naming <bart.lateur@skynet.be>
Question about code snippet <hafner-usenet@ze.tu-muenchen.de>
Re: Question about code snippet <krahnj@acm.org>
Reading a file <iqbals8@cs.man.ac.uk>
Regex help required <nobody@nowhere.com>
Re: Regex help required <meisl@amvt.tu-graz.ac.at>
Re: Regex help required (Philip Lees)
Regular Expression Syntax Checking <jap54@cornell.edu>
Re: Regular Expression Syntax Checking (Rafael Garcia-Suarez)
Re: RFC: FAQ3 update -- Using less memory <iltzu@sci.invalid>
Re: RFC: FAQ3 update -- Using less memory <joe+usenet@sunstarsys.com>
Re: Setting cookies in header to pass to Web Server? (BUCK NAKED1)
Re: Setting cookies in header to pass to Web Server? (Rafael Garcia-Suarez)
Re: Use PERL or Java? Which is faster? (Harri Haataja)
Re: Use PERL or Java? Which is faster? <noselasd@frisurf.no>
using post method <trautmann@niefert.de>
Re: using post method <Jerome.Abela@free.fr>
Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^ nobull@mail.com
Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^ (EED)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Mar 2001 08:47:51 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie: How do I count something in a file
Message-Id: <3AA5F713.32C4A671@acm.org>
petr zemanek wrote:
>
> Hi, everybody,
>
> what I need is a script that would count instances of a string
> in a file. It should look up for just the string, in this case
> it is numerals.
>
> The input file looks like this:
> 113 big
> 1 extraordinary
> 51 fine
> etc. (the divider is a tab).
>
> I need to count how many instances of words occurring e.g. once (and
> just once) are in the file.
>
> I wrote a script, but it is obviously not doing what I need (although
> it does not report any problems). The resulting number I get is "1",
> which is certainly wrong (it should give biiig numbers). Can anybody
> help me?
>
> Thanks a lot in advance.
>
> Petr Zemanek
>
> ----------------------------------
> Here is the script:
>
> #!/usr/local/bin/perl
#!/usr/local/bin/perl -w
use strict;
> #
> ##################
> # definition on what is being counted - in this case it's numerals
> # 1, but exactly this one, i.e. not number 100, 1000, 91, etc.
>
> $one = (1);
my $one = qr/\D1\D/;
> ############################
> # open file and read its contents to an array (@words)
my $file = 'file.txt';
> open FILE, 'file.txt';
> @words = FILE;
> close FILE;
open FILE, $file or die "Could not open $file: $!";
read FILE, $_, -s $file;
close FILE;
> #############################
> # counting of occurrences of numeral 1 ($one).
>
> foreach $one(@words){
> $count_one{$one}++;
> $count_one++;
> }; # end of this "foreach" cycle.
my $count_one = () = /$one/g;
> ####################
> # printing
>
> print $count_one, "\n";
print "$count_one\n";
__END__
John
------------------------------
Date: Wed, 07 Mar 2001 10:21:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Newbie: How do I count something in a file
Message-Id: <qr2catogqoifl2np3a72rpk1if6lfs461r@4ax.com>
petr zemanek wrote:
>The input file looks like this:
>113 big
>1 extraordinary
>51 fine
>etc. (the divider is a tab).
>
>I need to count how many instances of words occurring e.g. once (and
>just once) are in the file.
Homework? It sounds like it. I'll just get you on your way.
First, make a word counter program. Every time you find a word,
increment its entry in a count hash. So the keys are the words, the
values are the frequencies.
Next, select only those keys for which the count is 1 (perldoc -f grep).
--
Bart.
------------------------------
Date: Wed, 07 Mar 2001 11:37:23 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Newbie: How do I count something in a file
Message-Id: <3aa61a75.78690611@news.grnet.gr>
On Mon, 05 Mar 2001 16:35:14 +0100, petr zemanek
<petr.zemanek@ff.cuni.cz> wrote:
>what I need is a script that would count instances of a string
>in a file. It should look up for just the string, in this case
>it is numerals.
>
>The input file looks like this:
>113 big
>1 extraordinary
>51 fine
>etc. (the divider is a tab).
>#!/usr/local/bin/perl
See John Krahn's post about the use of -w and strict.
># definition on what is being counted - in this case it's numerals
># 1, but exactly this one, i.e. not number 100, 1000, 91, etc.
You need to be clear about this - do you want to count 1a or a1, for
example, or only the digit 1 on its own? Do you want to count multiple
occurences in the same line of the file, or just to count the total
number of lines that contain the search pattern? Will the search
pattern always be at the start of the line, followed by a tab, as it
is in your example data?
># open file and read its contents to an array (@words)
You don't need to read the entire file into memory - you can process
it one line at a time.
>open FILE, 'file.txt';
... or die ... (see John Krahn's post). You should always check the
success of a file open before proceeding.
>@words = FILE;
>foreach $one(@words){
my $count;
while (<FILE>){ #process file one line at a time
$count++ if /^1\t/;
}
The above counts the lines that start with the digit 1 followed by a
tab character. If this is not what you want, you will need to adapt
the regex accordingly. Se perlre for more.
Phil
--
@x=split//,'Just another Perl decoder,';split//,'*'x@x;%i=split/=/,
'AA=a=aa= =1=,';for$i(0..$#x){$_[$i]=chr($=+5);while($_[$i]ne$x[$i])
{$_[$i]=$i{$_[$i]}if$i{++$_[$i]};print@_,"\r";while(rand!=rand){}}}
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Wed, 07 Mar 2001 12:14:55 GMT
From: montep@about.com (Monte)
Subject: Re: Newbie: How do I count something in a file
Message-Id: <3aa725d7.2185923@news.hal-pc.org>
On Mon, 05 Mar 2001 16:35:14 +0100, petr zemanek
<petr.zemanek@ff.cuni.cz> wrote:
>Hi, everybody,
>
>what I need is a script that would count instances of a string
>in a file. It should look up for just the string, in this case
>it is numerals.
>
>The input file looks like this:
>113 big
>1 extraordinary
>51 fine
>etc. (the divider is a tab).
>
>I need to count how many instances of words occurring e.g. once (and
>just once) are in the file.
>
>I wrote a script, but it is obviously not doing what I need (although
>it does not report any problems). The resulting number I get is "1",
>which is certainly wrong (it should give biiig numbers). Can anybody
>help me?
>
>Thanks a lot in advance.
>
>Petr Zemanek
No code, you'll have to write your own. That's the best way to learn.
I will give you what I think I understand is your question, in a kind
of literal way.
open the file to be searched
while <file>{
if $tobefound is true
increment count
}
print $count
f your gonna spam.....
admin@loopback, $LOGIN@localhost, $LOGNAME@localhost,
$USER@localhost, $USER@$HOST, -h1024@localhost, root@mailloop.com
root@localhost, postmaster@localhost, admin@localhost, abuse@localhost
Chairman Reed Hundt: rhundt@fcc.gov
Commissioner James Quello: jquello@fcc.gov
Commissioner Susan Ness: sness@fcc.gov
Commissioner Rachelle Chong: rchong@fcc.gov
US Postal Service: customer@email.usps.gov
Fraud Watch: fraudinfo@psinet.com
Pyramid Schemes: pyramid@ftc.gov
Federal Trade Commission: consumerline@ftc.gov
net-abuse@nocs.insp.irs.gov
------------------------------
Date: Wed, 07 Mar 2001 12:45:13 GMT
From: harri@tolppa.kotisivupalvelu.fi (Harri Haataja)
Subject: Re: perl editors
Message-Id: <slrn9acb8s.f6q.harri@tolppa.kotisivupalvelu.fi>
Bill Feidt wrote:
>hanja@my-deja.com (hanja) wrote in <94np7f$483$1@nnrp1.deja.com>:
>
>>Out of curiousity, what editor do you use to write your scripts?
>
>vim
vim or any native vi (BSDs, mach etc)
--
Life -- Story by Kafka, illustration by Dali
------------------------------
Date: Wed, 07 Mar 2001 08:13:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl fortune database - where? (was: Dynamic naming of arrays or hashes)
Message-Id: <ndrbats7c5g7sdtb5443mutlohoume842i@4ax.com>
Richard J. Rauenzahn wrote:
> http://groups.google.com/groups?hl=en&lr=&group=comp.lang.perl.misc&safe=off&rnum=1&seld=940367237&ic=1
>
> (is there a shorter way to refer to an article on dejagoogle now?)
http://groups.google.com/groups?group=comp.lang.perl.misc&seld=940367237&ic=1
You only need "group", "seld" and "ic".
--
Bart.
------------------------------
Date: 07 Mar 2001 10:33:02 +0100
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Question about code snippet
Message-Id: <srjy9uhyldd.fsf@w3proj1.ze.tu-muenchen.de>
Hi there,
Three days ago I was confronted with a code snippet i _HAVE_ to use to
compute checksums from a string.
In the context the snippet is used, the string is a user-id and the
checksum is the assigned password for the user. Since the snippet is
used in other programs I don't have access to, it has to compute the
same password every time (obviously).
Unfortunately the snippet produces warnings when run with -w and
"strict". Since I normally use both, i want to get rid of them.
Here's the snippet:
###############################################################################
sub gen_passwd {
my ($uid) = @_;
my ($conv, $pw, $p, $i, $c);
$conv="0123456789";
$pw=passwd($uid,"secretpass",$uid); # local subroutine for PW computation
$p="";
for ($i=0; $i<length($pw),$i<8; $i++) {
$c=ord(substr($pw,$i,1));
$p.=substr($conv,$c%length($conv),1);
}
return $p;
}
###############################################################################
I want to keep as much of the code as possible, so I use $^W to get rid
of the warnings (ugly, I know). What bothers me is the
"$i<length($pw),$i<8"
part.
If I read it correct, "$i<length($pw)" is executed and the result is
thrown away, then "$i<8" is executed and used as termination constraint.
Obviously a bug. I think, the author wanted to use a "&&" instead.
(All the warnings in the substr constructs are handled by $^W ... hmpf!)
I just want to know if I can throw away the "$i<length($pw)" part
without altering the result of the algorithm. I really have no chance to
alter the programs that use this snippet. It is used throughout from our
SAP to our RADIUS server. :-(
-Walter
------------------------------
Date: Wed, 07 Mar 2001 11:38:54 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Question about code snippet
Message-Id: <3AA61F29.2DEF51F7@acm.org>
Walter Hafner wrote:
>
> Hi there,
Hi,
>
> [snip]
>
> Here's the snippet:
>
> ###############################################################################
> sub gen_passwd {
> my ($uid) = @_;
>
> my ($conv, $pw, $p, $i, $c);
>
> $conv="0123456789";
>
> $pw=passwd($uid,"secretpass",$uid); # local subroutine for PW computation
> $p="";
>
> for ($i=0; $i<length($pw),$i<8; $i++) {
> $c=ord(substr($pw,$i,1));
> $p.=substr($conv,$c%length($conv),1);
> }
> return $p;
> }
> ###############################################################################
>
> I want to keep as much of the code as possible, so I use $^W to get rid
> of the warnings (ugly, I know). What bothers me is the
> "$i<length($pw),$i<8"
> part.
>
> If I read it correct, "$i<length($pw)" is executed and the result is
> thrown away, then "$i<8" is executed and used as termination constraint.
Yes, this is correct.
> Obviously a bug. I think, the author wanted to use a "&&" instead.
>
> (All the warnings in the substr constructs are handled by $^W ... hmpf!)
>
> I just want to know if I can throw away the "$i<length($pw)" part
> without altering the result of the algorithm. I really have no chance to
> alter the programs that use this snippet. It is used throughout from our
> SAP to our RADIUS server. :-(
After running the code it looks like the intention is to return an eight
byte checksum. When the length of $pw is less than 8 it pads the
remaining bytes with 0 (zero). The following will produce the same
results with no warnings:
sub gen_passwd {
my ($uid) = @_;
my $pw = passwd( $uid, "secretpass", $uid ); # local subroutine for
PW computation
return join '', map { ord($_) % 10 } (split //, $pw .
"\0\0\0\0\0\0\0\0")[0 .. 7];
}
HTH
John
------------------------------
Date: Wed, 07 Mar 2001 10:39:37 +0000
From: Shazad Iqbal <iqbals8@cs.man.ac.uk>
Subject: Reading a file
Message-Id: <3AA60FE9.DC8F53CE@cs.man.ac.uk>
Hi
I am trying to extract all the vital details from a file usinf regular
expressions. I cant seem to get the hang of the matching clauses. The
code below shows what I have done but I can only match the first part of
the line in the file.
#!/opt/perl/bin/perl -w
use strict;
my (
$PRINCIPLE_GROUP,
$EXAMPLE_CLASSES_OR_LAB,
$USERNAME,
$MODULES,
@PRINCIPLE_GROUP,
@EXAMPLE_CLASSES_OR_LAB,
@USERNAME,
@MODULES,
$index );
my $userfile = "First_year_modules";
$| = 1;
open DATA, $userfile or die "Could not open file: $!";
# Y/1112E=Th15a,1412=W,1412E=Th15b,MT1662E=Mo16,Unix12=S1 akrami0 1011
1021 1031 1041 1052 1062 1072 1112 1211 1311 1412 MT1662
# ABIS brodiejx 1511 1522 1532
# W/1112E=Tu10a,Unix12=S1 brownea0 1011 1021 1031 1041 1052 1062 1072
1112 1211 1222 1311 MT1672
# Group/ Example Clases Username Modules
while (<DATA>)
{
chomp;
if ( m{^([a-zA-Z-]+)| # principle group
\/|\s+
# split by / or space
#(\d+)(\w)=(\w{2})(\d{2})([ab]) # course number,second group = day,
time and week
#,
(.*) # the modules which they have examples class and when they have
them = modules_info
\s+
([a-zA-Z0-9]+) # username
\s+
(.*) # modules
\n
}x # ignore
)
{
push(@PRINCIPLE_GROUP,$1);
#push (@MODULE,$2;)
#push (@EXAMPLES_CLASS,$3);
#push (@DAY,$4);
#push (@TIME,$5);
#push (@WEEK,$6);
push(@EXAMPLE_CLASSES_OR_LAB ,$2);
push(@USERNAME,$3);
push(@MODULES,$4);
}
#print "Principle Group $1\.\n";
print "all example clesses $2.\n";
#print "$3 in Principle group $1\t doing $2\t with these modules
$4\n";
}
print "what is your username ?\n\n";
my $username_input = <STDIN>;
chomp $username_input;
print "Your username is $username_input\n";
my $match = 0;
for ($index=0; $index <= $#USERNAME; $index++)
{
if ( $USERNAME[$index] =~ /$username_input/)
{
$match = 1;
print " the module he/she does are $MODULES[$index], in group
$PRINCIPLE_GROUP[$index].\n";
last;
}
}
if (!$match) { print "You have not typed in an incorrect username\n";}
close DATA;
Because of the varaitions I have to catch I dont know how to catch them
all.
Can anyone help me or put me in the correct derection?
Thanks for your time
Shazad Iqbal
------------------------------
Date: Wed, 07 Mar 2001 12:50:32 GMT
From: "Maggie Simpson" <nobody@nowhere.com>
Subject: Regex help required
Message-Id: <s8qp6.4987$6A6.2626583@typhoon2.ba-dsg.net>
Hi,
I've been playing around with regex's but am still having difficulty
achieving exactly what I
want to do. Any helpful comments would be appreciated.
What I want to do is, given a string, remove certain parts of it - but the
middle parts of the
string will vary each time, and there will usually be more than one removal
required. The middle
parts (the bits that vary) will also be of different lengths.
eg:
Imagine I have the following string:
"djagdajxdvAJLDKJDHGAK193731DAD - <A
HREF=domain.com\dir\XXXXXX>STATIC</A> - bdsk
hdakidhaodq9eyu8o- <A HREF=domain.com\dir\YYYYY>STATIC</A> - END
OF STRING"
where I need to remove all occurences of "- <A
HREF=domain.com\dir\?????>STATIC</A> -"
where ????? is the part which will be different each time, but where the
description, STATIC, will
remain the same. ie, I want to end up with a string that looks like the one
below:
"djagdajxdvAJLDKJDHGAK193731DAD bdsk hdakidhaodq9eyu8o END OF STRING"
Many thanks,
George
------------------------------
Date: 07 Mar 2001 14:07:59 +0100
From: Christian Meisl <meisl@amvt.tu-graz.ac.at>
Subject: Re: Regex help required
Message-Id: <m3zoexu3ps.fsf@famvtpc59.tu-graz.ac.at>
"Maggie Simpson" <nobody@nowhere.com> writes:
> Imagine I have the following string:
>
> "djagdajxdvAJLDKJDHGAK193731DAD - <A
> HREF=domain.com\dir\XXXXXX>STATIC</A> - bdsk
> hdakidhaodq9eyu8o- <A HREF=domain.com\dir\YYYYY>STATIC</A> - END
> OF STRING"
>
> I want to end up with a string that looks like the one below:
>
> "djagdajxdvAJLDKJDHGAK193731DAD bdsk hdakidhaodq9eyu8o END OF STRING"
$string =~ s/\s+\-\ \<A HREF=domain.com\\dir\\.*?\>STATIC\<\/A\>\ \-\s+/ /g;
Regards,
Christian
--
Christian Meisl <meisl@amvt.tu-graz.ac.at> www.amft.tu-graz.ac.at
Inst. f. Apparatebau, Mech. Verfahrenstechnik und Feuerungstechnik
------------------ New systems generate new problems. ------------------
PGP fingerprint: DF48 2503 0411 F0EF 149C 851B 1EF0 72B9 78B6 034A
------------------------------
Date: Wed, 07 Mar 2001 13:52:24 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Regex help required
Message-Id: <3aa63aa6.86931470@news.grnet.gr>
On Wed, 07 Mar 2001 12:50:32 GMT, "Maggie Simpson"
<nobody@nowhere.com> wrote:
>Imagine I have the following string:
>
>"djagdajxdvAJLDKJDHGAK193731DAD - <A
>HREF=domain.com\dir\XXXXXX>STATIC</A> - bdsk
>hdakidhaodq9eyu8o- <A HREF=domain.com\dir\YYYYY>STATIC</A> - END
>OF STRING"
>
>where I need to remove all occurences of "- <A
>HREF=domain.com\dir\?????>STATIC</A> -"
>where ????? is the part which will be different each time, but where the
>description, STATIC, will
>remain the same. ie, I want to end up with a string that looks like the one
>below:
>
>"djagdajxdvAJLDKJDHGAK193731DAD bdsk hdakidhaodq9eyu8o END OF STRING"
>George
George (or Maggie), if you are _sure_ that the parts you want to
remove will always start with - and end with -, AND you
are _sure_ that there are no other parts that start and end in that
way, then the following will work:
$string =~ s/- .*? -//g;
Given your example, you can also make this more specific:
$string =~ s/- <A.*?A> -//g;
However, this looks as if it might be an HTML parsing problem, so you
may want to look into some of the modules that do that kind of thing.
HTH.
Phil
--
@x=split//,'Just another Perl decoder,';split//,'*'x@x;%i=split/=/,
'AA=a=aa= =1=,';for$i(0..$#x){$_[$i]=chr($=+5);while($_[$i]ne$x[$i])
{$_[$i]=$i{$_[$i]}if$i{++$_[$i]};print@_,"\r";while(rand!=rand){}}}
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Wed, 7 Mar 2001 08:20:19 -0500
From: "John A. Parker" <jap54@cornell.edu>
Subject: Regular Expression Syntax Checking
Message-Id: <985ck0$4fh$2@news01.cit.cornell.edu>
I have written a Perl daemon to monitor system syslog messages for strings
matching administrator supplied regular expressions. These strings are
created by the individual administrators via a forms based web interface.
Because of the problems inherent in capturing string representations of
regular expressions without actually treating them as such during the
creation process, I had to resort to very ugly, temporary character
translations, and have managed to expose the program to very weird behavior
when erroneous (read as "partial" or "incomplete") regular expressions are
entered by the users.
I have avoided developing a "regular expression syntax checker" as I'm sure
any effort on my part would be incomplete and most likely inaccurate.
Can anyone point me to a Perl built-in or someone else's package that I
could use to:
- Accept a form inputted string that may or may not include regular
expression syntax,
- Validate any regular expressions that are included, and
- "Package" the string so the process of passing from point to point and
into and out of flat files can be done without the string being evaluated?
------------------------------
Date: Wed, 07 Mar 2001 13:45:00 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Regular Expression Syntax Checking
Message-Id: <slrn9aceqg.te5.rgarciasuarez@rafael.kazibao.net>
John A. Parker wrote in comp.lang.perl.misc:
> I have written a Perl daemon to monitor system syslog messages for strings
> matching administrator supplied regular expressions. These strings are
> created by the individual administrators via a forms based web interface.
Yeah! Web-based interface for sysadmins. That cuts edge. Most useful
when the web server crashes. Just half-kidding ;-)
> Because of the problems inherent in capturing string representations of
> regular expressions without actually treating them as such during the
> creation process, I had to resort to very ugly, temporary character
> translations, and have managed to expose the program to very weird behavior
> when erroneous (read as "partial" or "incomplete") regular expressions are
> entered by the users.
I don't see what you have done so far; however, and IMHO, you should
read about qr// in the perlop manpage and about eval in the perlfunc
manpage. This should point you in some right direction.
> I have avoided developing a "regular expression syntax checker" as I'm sure
> any effort on my part would be incomplete and most likely inaccurate.
You're right. As someone once said, "only perl can parse Perl".
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 6 Mar 2001 23:30:30 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <983921278.13055@itz.pp.sci.fi>
In article <3AA56BEC.A7F9F0CD@home.com>, Michael Carman wrote:
>
>=item * Consider using C<eval BLOCK>
>
>If you need to initialize a large variable in your code, you
>might consider doing it with an eval statement like this:
>
> my $large_string = eval ' "a" x 5_000_000 ';
Hmm.. surely that's C<eval EXPR> rather than C<eval BLOCK>?
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"These fine people, forming the dot in ROOT-SERVERS DOT NET DOT have given
us a bloody SERVICE PACK!" -- Pim van Riezen in the monastery
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: 06 Mar 2001 20:13:44 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <tWfp6.3134$L67.58901@news1.atl>
Michael Carman <mjcarman@home.com> writes:
> Joe Schaefer wrote:
> >
> > Michael Carman <mjcarman@home.com> writes:
> >>
> >> =item * Don't slurp!
> >>
> >> [...]
> >
> > and B<never> use this:
> >
> > for (<FILE>) {
> > # ...
> > }
>
> Does that really hit memory harder than the explicit slurp, or is it
> just ugly?
Dunno, but it's certainly worse than
while (<FILE>) {
#...
}
which is what you recommended to use. I can't think of a
situation where "for(<FILE>)" would be reasonable, yet I've
seen it appear in clp.misc on occasion. I just thought an
explicit "don't do this" was warranted for the FAQ.
[...]
> > ... If your copy consumes a large amount of RAM, you may want
> > to explicitly undef() your copy once you are no longer need it. Perl
> > might then return the additional memory back to the OS.
>
> Hmm. I'd agree with you if not for what Ilya said in another branch of
> this thread. It *should* help, but will it?
If I understood Ilya correctly, he was discussing perl's internal reuse
(or lack thereof) for memory allocated to lexicals. undef()'ing a
_large_ variable usually (1) causes perl to return the memory to the OS.
Generally I don't think there's anything to be gained (2) by undef()ing
lots of "normal-sized" variables, and it's certainly not a very Perl-ish
thing to do.
(1) - anecdotal to be sure, but it works for me on linux with 5.005_03
or better. There was thread about a month ago where Jerome Abela and
I were trying to flesh this out via trial and error, and most of the
remarks I made here were based on that discussion:
http://groups.google.com/groups?hl=en&lr=&safe=off&ic=1&th=4cd94c0e0cebbc1c&seekd=931558565#931558565
Of course, an expert like Ilya who is intimately familiar with the gc
could certainly do a better job than I did.
(2) a Silvio Dante-ism
Best.
--
Joe Schaefer "If you pick up a starving dog and make him prosperous, he will
not bite you. This is the principal difference between a dog and
a man."
--Mark Twain
------------------------------
Date: Wed, 7 Mar 2001 02:15:52 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Setting cookies in header to pass to Web Server?
Message-Id: <15297-3AA5EE38-1@storefull-248.iap.bryant.webtv.net>
I have a similar problem where I try to use cookies. Someone gave me
this coding to bypass server default pages when getting and storing a
URL. After I working on it for 2 days, I still can't get it to work like
I want, but maybe it will help you.
This particular coding attempts to bypass a webhost's default page, grab
a zip file, and store it in $tmpfile. It appears to work, but it prints
the header info to $tmpfile which I don't want.
my ($err_msg, $data) = &hackhost($url);
if ($err_msg) {
print "Error: $err_msg.\n";
}
elsif (open(TFILE, ">$tmpfile")) {
binmode(TFILE);
print TFILE $data;
close(TFILE);
}
else {
print "Error: could not saved retrieved data - $!.\n";
}
sub hackhost {
my ($url) = @_;
my $data = '';
my $err_msg = '';
Err: {
my $url_data = $url;
my $url_html = $url;
$url_html =~ s!/([^/]*)$!/!o; # strip to folder
use LWP;
use HTTP::Request;
use HTTP::Cookies;
use HTTP::Headers;
use LWP::UserAgent;
my $request = ();
my $response = ();
# Make initial request to the first page. This makes things
# "look good" to any smart observers on the far side. We also
# catch the first cookie and persist it:
my $ua = new LWP::UserAgent;
my $headers = new HTTP::Headers;
my $cookie_jar = new HTTP::Cookies;
# Simulate IE 5.5 browser:
$ua->agent( 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
$headers->header(
'HTTP_ACCEPT' => 'application/x-tar,
application/zip',
'HTTP_ACCEPT-ENCODING' => 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,
ko;q=0.7,ja;q=0.3',
'HTTP_CONNECTION' => 'close',
'HTTP_REFERER' => '',
);
# Request initial HTML page:
$request = new HTTP::Request('GET' => $url);
$response = $ua->request( $request);
$cookie_jar->extract_cookies( $response );
unless ($response->is_success()) {
$err_msg = $response->error_as_HTML();
next Err;
}
# Request follow-up page, using simulated REFERER and cookies:
$headers->header('HTTP_REFERER' => $url_html);
$request = new HTTP::Request('GET' => $url_data);
$cookie_jar->add_cookie_header( $request );
$response = $ua->request( $request );
$cookie_jar->extract_cookies( $response );
unless ($response->is_success()) {
$err_msg = $response->error_as_HTML();
next Err;
}
$data = $response->as_string();
last Err;
}
return ($err_msg, $data);
};
Regards,
--Dennis
------------------------------
Date: Wed, 07 Mar 2001 09:26:27 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Setting cookies in header to pass to Web Server?
Message-Id: <slrn9abvlm.sjl.rgarciasuarez@rafael.kazibao.net>
BUCK NAKED1 wrote in comp.lang.perl.misc:
> I have a similar problem where I try to use cookies. Someone gave me
> this coding to bypass server default pages when getting and storing a
> URL. After I working on it for 2 days, I still can't get it to work like
> I want, but maybe it will help you.
>
> This particular coding attempts to bypass a webhost's default page, grab
> a zip file, and store it in $tmpfile. It appears to work, but it prints
> the header info to $tmpfile which I don't want.
>
[...snipping code...]
>
> $data = $response->as_string();
You should use $response->content() here if you don't want headers to
show up.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 07 Mar 2001 11:27:43 GMT
From: harri@tolppa.kotisivupalvelu.fi (Harri Haataja)
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <slrn9ac6nj.f6q.harri@tolppa.kotisivupalvelu.fi>
Terrence Brannon wrote:
>Kenny Pearce <kenny@kennypearce.net> writes:
>
>> actually, I just recently read the article at Perl.com on gtk+ programming in
>> Perl. I didn't know until I read it that you could make GUIs in perl! now that I
>> know this, I'm not sure I'll use Java for anything other than web applets.
>
>But think about Perl/Tk instead of gtk+. More stable and what you
>learn will allow you to use Tk on multiple programming languages.
I have been recently wondering on what UI could I use with the perl things
I keep as pets. =)
GTK is nice and looks good and all but is an absolute pig when used over a
network. I also don't want to use/learn/install tk. I'm looking at Motif
(cpan: X11) now as that would seem appropriate for the sparc/HP environment.
Any other views?
--
Life -- Story by Kafka, illustration by Dali
------------------------------
Date: Wed, 7 Mar 2001 14:36:38 +0100
From: "Nils O. Selåsdal" <noselasd@frisurf.no>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <kPqp6.9630$t21.247026@news3.oke.nextra.no>
"Harri Haataja" <harri@tolppa.kotisivupalvelu.fi> wrote in message
news:slrn9ac6nj.f6q.harri@tolppa.kotisivupalvelu.fi...
> Terrence Brannon wrote:
> >Kenny Pearce <kenny@kennypearce.net> writes:
> >
> >> actually, I just recently read the article at Perl.com on gtk+
programming in
> >> Perl. I didn't know until I read it that you could make GUIs in perl!
now that I
> >> know this, I'm not sure I'll use Java for anything other than web
applets.
> >
> >But think about Perl/Tk instead of gtk+. More stable and what you
> >learn will allow you to use Tk on multiple programming languages.
visualtcl , a great building GUI with tcl, get it at www.sourceforge.org
> I have been recently wondering on what UI could I use with the perl things
> I keep as pets. =)
>
> GTK is nice and looks good and all but is an absolute pig when used over a
> network. I also don't want to use/learn/install tk. I'm looking at Motif
> (cpan: X11) now as that would seem appropriate for the sparc/HP
environment.
I'd really take a serious look at Qt if i vere you, its clean, looks nice
and easyto
use yet powerful. And crossplatform across most unix and windows.
www.trolltech.no
or www.kde.org to see the power of it ;)
------------------------------
Date: Sun, 4 Mar 2001 15:56:22 +0100
From: "Martin Trautmann" <trautmann@niefert.de>
Subject: using post method
Message-Id: <9858cq$j8d$01$1@news.t-online.com>
hi,
i am trying to submit multiple queries, i.e. instead of having to press the
submit button
of a form several times i am trying to get that done with a perl script
using the post method.
i thought this would be the easiest way...
use HTTP::Request::Common;
POST 'http://www.main-rheiner.de/voting/vote.php3',
[ id => '25',
vote => '2',
];
unfortunately this is not working, where can i find additional help ?!?
tks
martin
------------------------------
Date: Wed, 07 Mar 2001 13:49:53 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: using post method
Message-Id: <3AA63B67.774F0E8E@free.fr>
Martin Trautmann wrote :
> use HTTP::Request::Common;
>
> POST 'http://www.main-rheiner.de/voting/vote.php3',
> [ id => '25',
> vote => '2',
> ];
It's not enough to build a request. You need to send it to the right
server, with an agent using the right protocol.
What you're looking for is LWP::UserAgent. See LWP::UserAgent doc for
straightforward examples.
Jerome.
--
()
/\
------------------------------
Date: 07 Mar 2001 13:03:42 +0000
From: nobull@mail.com
Subject: Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^([\d.]+)$/ ? $1 : 'null'
Message-Id: <u9zoexybm9.fsf@wcl-l.bham.ac.uk>
"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
> nobull@mail.com wrote:
> > Change $1 to "$1".
>
> Thanks for you reply!
>
> > print ( 'foo'=~/(.*)/ ? $1 : '', 'bar'=~/(.*)/ ? $1 : ''); # barbar
> > print ( 'foo'=~/(.*)/ ? "$1" : '', 'bar'=~/(.*)/ ? "$1" : ''); # foobar
>
> That is very strange, why does it happen?
Because the ?: and , operators operate on lvalues.
> Is it the result of some optimization of the print function?
No, it applies to lists in all contexts.
#!/usr/bin/perl
use strict;
use warnings;
my $q;
sub set_q { $q = shift; return "\$q=$q" }
my @l1 = ( set_q('foo'), $q, set_q('bar'), $q);
my @l2 = ( set_q('foo'), "$q", set_q('bar'), "$q");
print "\@l1: @l1\n\@l2: @l2\n";
__END__
@l1: $q=foo bar $q=bar bar
@l2: $q=foo foo $q=bar bar
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 07 Mar 2001 09:55:17 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^([\d.]+)$/ ? $1 : 'null'
Message-Id: <3AA5F775.6A44D056@eed.ericsson.se>
nobull@mail.com wrote:
> Change $1 to "$1".
Thanks for you reply!
> print ( 'foo'=~/(.*)/ ? $1 : '', 'bar'=~/(.*)/ ? $1 : ''); # barbar
> print ( 'foo'=~/(.*)/ ? "$1" : '', 'bar'=~/(.*)/ ? "$1" : ''); # foobar
That is very strange, why does it happen? Is it the
result of some optimization of the print function?
> Perhaps when the FAQ says quoting variables is wrong 99.8% of the time
> it should explain the 0.2%
Regards
Alex
------------------------------
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 434
**************************************