[16230] in Perl-Users-Digest
Perl-Users Digest, Issue: 3642 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 12 18:15:52 2000
Date: Wed, 12 Jul 2000 15:15:35 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963440135-v9-i3642@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 12 Jul 2000 Volume: 9 Number: 3642
Today's topics:
Re: multidimensional associative arrays <phil.rennert@ioip.com>
Re: multidimensional associative arrays <nospam@nospam.com>
Re: Need Help with array (should be easy!) <nospam@nospam.com>
Re: Need Help with array (should be easy!) <lr@hpl.hp.com>
Re: Need Help with array (should be easy!) <btrieger@mediaone.net>
Re: need post/lwp example <billw@dal.asp.ti.com>
Re: Net::SMTP question <postmaster@rask.nospam.kampsax.k-net.dk>
Net::XWhois 0.67 (Vipul Ved Prakash)
nettoyage de glossaires sous Excel... et Perl là-dedans <drich@creditlyonnais.club-internet.fr>
Re: Never satisfied <lr@hpl.hp.com>
Re: New to perl, need help <nospam@nospam.com>
Re: New to perl, need help <tony_curtis32@yahoo.com>
Re: New to perl, need help <uri@sysarch.com>
Re: New to perl, need help (Randal L. Schwartz)
Re: New to perl, need help <aqumsieh@hyperchip.com>
Re: New to perl, need help <lr@hpl.hp.com>
Re: Odd problem with qx in ActivePerl <bart.lateur@skynet.be>
PRINTing " "" " <jdNOjdSPAM@syncon.ie.invalid>
Re: PRINTing " "" " <care227@attglobal.net>
Re: PRINTing " "" " <jdNOjdSPAM@syncon.ie.invalid>
Re: PRINTing " "" " <uri@sysarch.com>
Re: Raise Exception when failure occurs ?? <bart.lateur@skynet.be>
Reading a line into variables: Question kiran_mamidi@my-deja.com
Re: Reading a line into variables: Question <care227@attglobal.net>
Re: Reading a line into variables: Question timhood@bigfoot.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 12 Jul 2000 13:51:55 -0400
From: Philip Rennert <phil.rennert@ioip.com>
Subject: Re: multidimensional associative arrays
Message-Id: <396CB03B.9D0FB222@ioip.com>
>
> >How do you do the same thing for associative arrays? What you showed me I think
> >works only on the first index, because how can Perl know that in $a{Fred} you mean
> >Fred to be in the third index, say...
>
> Of course it works:
>
> foreach my $j (keys %{ $a{foo} }) {
> foreach my $k (keys %{ $a{foo}{$j}{bar} }) {
>
> print $a{foo}{$j}{bar}{$k}, "\n";
>
> }
> }
Okay, thank you: that was the syntax I was looking for: in each loop you list the
indices up to that point and do a keys on the current one. Thanks for the Jeopardy
definitions, everyone; I hope everyone's happy this comment's down here...
------------------------------
Date: 12 Jul 2000 19:13:11 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: multidimensional associative arrays
Message-Id: <8kig07$6b7$1@216.155.32.201>
In article <396C6C63.7D7AE5EA@ioip.com>, Philip Rennert <phil.rennert@ioip.com>
wrote:
| I don't know what you mean by "Jeopardy style".
| Am I not stating this clearly? With a non-associative array, you can
| specify the
| values of any indices you want, and vary the others, like
| $a[4][$j][6][$k], inside
| loops on $j and $k.
| How do you do the same thing for associative arrays? What you showed me I
| think
| works only on the first index, because how can Perl know that in $a{Fred}
| you mean
| Fred to be in the third index, say...
"jeopardy style" is putting the answer BEFORE the question instead of after.
Typically considered bad netiquette, and makes it look as though you never
bothered to read the entire answer before replying to it.
Also your linewrapping is seriously screwed up (see above).
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: 12 Jul 2000 20:04:59 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: Need Help with array (should be easy!)
Message-Id: <8kij1b$6b7$5@216.155.32.201>
In article <tTJa5.10$%c7.28282@news.pacbell.net>, "Calvin Crutchfield"
<calvin@namezero.com> wrote:
| I have very large log files. sometimes upwards of 200mb
|
| I am having trouble reading a field into an array, because of memory
| limitations (1gbRam) Sun Netra T1 ... It would be 1,000,000 + items. (I
| am
| dealing with a large list of domain names ). So I have to process one
| line
| at a time. But now I want to know how many of these 1million plus names
| are
| unique. If I could suck them in to an array, I could sort the array and
| then find out how many are unique (but how??). Now throw in the fact the
| data is too large, what do I do?
|
| So, how do you sort an array AND count ONLY the unique items in it?
| how do you do the same if you cant get them into an array?
Unix.
a favorite example of mine as to the appropriateness of a tool for the right job
is this:
when you have bosses who say "here's a couple gigabytes of log files
from our web servers. How many different IP addresses are in there?".
On Unix, that question could be answered with this:
cat *.log | sed 's/ .*//' | sort | uniq | wc -l
doubtless this could be slightly rewritten to solve your problem. :)
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Wed, 12 Jul 2000 13:39:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Need Help with array (should be easy!)
Message-Id: <MPG.13d6774ba53254ce98abc3@nntp.hpl.hp.com>
[Removed alt.perl.]
In article <8kij1b$6b7$5@216.155.32.201> on 12 Jul 2000 20:04:59 GMT,
The WebDragon <nospam@nospam.com> says...
...
> when you have bosses who say "here's a couple gigabytes of log files
> from our web servers. How many different IP addresses are in there?".
> On Unix, that question could be answered with this:
>
> cat *.log | sed 's/ .*//' | sort | uniq | wc -l
Two processes too many.
sed 's/ .*//' *.log | sort -u | wc -l
And now we return you to your regularly scheduled Perl program.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 12 Jul 2000 21:15:03 GMT
From: "btrieger" <btrieger@mediaone.net>
Subject: Re: Need Help with array (should be easy!)
Message-Id: <rd5b5.4041$jE1.156450@typhoon.ne.mediaone.net>
The WebDragon <nospam@nospam.com> wrote
> <calvin@namezero.com> wrote:
>
> | I have very large log files. sometimes upwards of 200mb
> |
> | I am having trouble reading a field into an array, because of memory
> | limitations (1gbRam) Sun Netra T1 ... It would be 1,000,000 + items.
(I
> | am
> | dealing with a large list of domain names ). So I have to process one
> | line
> | at a time. But now I want to know how many of these 1million plus
names
> | are
> | unique. If I could suck them in to an array, I could sort the array
and
> | then find out how many are unique (but how??). Now throw in the fact
the
> | data is too large, what do I do?
> |
> | So, how do you sort an array AND count ONLY the unique items in it?
> | how do you do the same if you cant get them into an array?
>
> Unix.
>
> a favorite example of mine as to the appropriateness of a tool for the
right job
> is this:
>
> when you have bosses who say "here's a couple gigabytes of log files
> from our web servers. How many different IP addresses are in there?".
> On Unix, that question could be answered with this:
>
> cat *.log | sed 's/ .*//' | sort | uniq | wc -l
Use a hash and then count the keys.
IE.
my %hash;
while (<LOGFILE>) {
my $dom = (split /\s/,$_)[0];
$hash{$dom}++;
}
my $domains = keys %hash;
The above code was written on the fly and not tested
Good luck
------------------------------
Date: Wed, 12 Jul 2000 13:27:44 -0500
From: Bill Webster <billw@dal.asp.ti.com>
Subject: Re: need post/lwp example
Message-Id: <396CB8A0.5059CCD@dal.asp.ti.com>
Ilmari Karonen wrote:
> In article <396A3D30.DEC49AD3@dal.asp.ti.com>, Bill Webster wrote:
> > #!/usr/bin/perl
> > use LWP::UserAgent;
> > $ua = LWP::UserAgent->new;
> >
> > my $req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/BugGlimpse');
> > $req->content_type('application/x-www-form-urlencoded');
> > $req->content('match=www&errors=0');
> >
> > my $res = $ua->request($req);
> > print $res->as_string;
> >
> > ...well http://www.perl.com/cgi-bin/BugGlimpse no longer exists, so
> >its hard for me to play with this example.
>
> Well, just pick any old script. It'd probably be best for you to run
> your own test script, but you can play with one of mine if you want:
>
> my $req = HTTP::Request->new(POST => 'http://www.sci.fi/~iltzu/cgi-bin/figlet.pl');
> $req->content_type('application/x-www-form-urlencoded');
> $req->content('text=Hello,+world!&font=big');
>
> --
> Ilmari Karonen - http://www.sci.fi/~iltzu/
> "The screwdriver *is* the portable method." -- Abigail
> Please ignore Godzilla and its pseudonyms - do not feed the troll.
Tried this last night and it worked great. Thanks so much for the help. Now
I know I'm going about this thing correctly , and can try to debug what I
wrote . My problem must be name/value pairs....
Bill
------------------------------
Date: 12 Jul 2000 20:12:14 +0200
From: "Rask Ingemann Lambertsen" <postmaster@rask.nospam.kampsax.k-net.dk>
Subject: Re: Net::SMTP question
Message-Id: <1582.228T700T12123308postmaster@rask.nospam.kampsax.k-net.dk>
On 10-Jul-00 20:13:24, yong321 wrote the following about "Net::SMTP question":
> My program loops for each person and sends email like this:
> $smtp=Net::SMTP->new($mailserver);
> foreach $person (@person) {
> $smtp->mail("$return_address");
$smtp->recipient($person);
is missing here.
> #do other stuff like $smtp->datasend(), ->dataend(), etc.
> }
> $smtp->quit;
> My question is, do I also need to put the first and last lines shown
> above in the foreach block? I don't think I need to create the $smtp
> object, destroy it, and recreate it for the next person, but not sure.
If you look strictly at the SMTP protocol, then the state after sending
an email is the same as right after HELO/EHLO. So your example should be
fine unless Net::SMTP puts further restrictions on what you are allowed to
do.
Note that
$smtp=Net::SMTP->new($mailserver);
$smtp->mail("$return_address");
foreach $person (@person) {
$smtp->recipient($person);
}
#do other stuff like $smtp->datasend(), ->dataend(), etc.
$smtp->quit;
would be much faster.
You should definitely read RFC 821, RFC 1123 and other RFCs about the
SMTP protocol. You should also read RFC 822 about the message format, etc.
Regards,
/¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯T¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\
| Rask Ingemann Lambertsen | postmaster@rask.nospam.kampsax.k-net.dk |
| A4000, 896 kkeys/s (RC5-64) | "ThrustMe" on XPilot and EFnet IRC |
| If you wake up Sleepy & Grumpy, you must be Snow White. |
------------------------------
Date: 9 Jul 2000 06:58:13 GMT
From: vipul@shell2.ba.best.com (Vipul Ved Prakash)
Subject: Net::XWhois 0.67
Message-Id: <_B2b5.324$O7.49119@news-east.usenetserver.com>
Net::XWhois
A generic whois client interface class for Perl.
Version
0.67
Changes in 0.67
Better error handling capabilities. Refer to POD documentation for
details.
Brief Description
The Net::XWhois class provides a generic client framework for doing Whois
queries and parsing server response.
The class maintains an array of whois servers and associated lists of top
level domains they serve for transparently selecting servers appropriate for
different queries. The server details are, therefore, hidden from the user;
"vipul.net" (from InterNIC), gov.ru (from RIPE) and "bit.ch" (from
domreg.nic.ch) are queried in the same manner. This behaviour can be over-
ridden by specifying different bindings at object construction or by
registering associations with the class.
One of the more important features of this module is to enable the design of
consistent and predictable interfaces to incompatible whois response
formats. The Whois RFC (954) does not define a template for presenting
server data; consequently there is a large variation in layout styles as
well as content served across servers.
To overcome this Net::XWhois maintains another set of tables, parsing rule-
sets, for a few, popular response formats. These parsing tables contain
section names (labels) together with regular expressions that match the
corresponding section text. The section text is accessed via these labels
which are available as data instance methods at runtime. By following a
consistent nomenclature for labels, semantically related information encoded
in different formats can be accessed with the same methods.
Comments, suggestions
Vipul Ved Prakash <mail@vipul.net>
------------------------------
Date: Wed, 12 Jul 2000 23:37:35 +0200
From: "Nicolas Soccol" <drich@creditlyonnais.club-internet.fr>
Subject: nettoyage de glossaires sous Excel... et Perl là-dedans ?
Message-Id: <8kioel$im5$1@front1.grolier.fr>
Bonjour !
je suis actuellement en stage dans une boîte de traduction / localisation et
ma tâche
consiste à constituer des glossaires sous excel, associant sur 2 colonnes un
mot et sa traduction.
Comme beaucoup de mini glossaires sont déjà existants sous différentes
versions,
il faut que je les réunisse en un seul, pour ensuite les "nettoyer" des
caractères
spécifiques aux programmes d'où ils sont extraits, du genre : %N, #, \n, <>,
et tout ce qui est chiffres, signes
de ponctuation,doublons, lignes vides...etc (pour doublons et lignes vides
c'est bon j'ai trouvé)
Le truc chiant, c'est qu'Excel2000 n'est pas au top pour ce qui est
manipulation de
caractères : son chercher/remplacer est très limité...
résultat, je dois me taper toute la feuille ligne par ligne pour faire un
bon tri !!!
Voilà ce que je cherche : il doit bien y avoir moyen d'automatiser un tant
soit peu ce travail
de fourmi, de trouver un programme en Perl qui permette de faciliter le tri,
quitte à exporter
le tableau excel en .txt ou une astuce quelconque...
Le problème est que je ne suis pas informaticien, je ne sais pas programmer
en Perl (ni VBasic)et je
n'ai pas le temps d'apprendre en rentrant du boulot.....
Si une bonne âme parmi vous a une solution, des conseils, ou quoi que ce
soit qui
puisse me venir en aide...surtout n'hésitez pas ! Merci
NS
adresse à privilégier pour toute réponse:
soccol.n@linguex.fr
------------------------------
Date: Wed, 12 Jul 2000 12:21:41 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Never satisfied
Message-Id: <MPG.13d6651d27fd588b98abc0@nntp.hpl.hp.com>
In article <8ki887$5bq$1@pegasus.csx.cam.ac.uk> on 12 Jul 2000 17:00:55
GMT, M.J.T. Guy <mjtg@cus.cam.ac.uk> says...
> In article <396c3d98@news.telinco.net>, John <john@nomailplease> wrote:
...
> > $alpha = $numeric = $string_in;
> > $alpha =~ s/[\W]|[\d]//g; # remove any non letters
> > $numeric =~ s/[\D]//g; # remove any non digits
>
> The standard paradigm for "make a copy and update it" is
>
> ($alpha = $string_in) =~ s/[\W\d]//g
> ($numeric = $string_in) =~ s/\D//g;
Yes, that is the standard paradigm for "make a copy and update it"
(assuming a semicolon on the first line :-). But that isn't the best
way to do character-wise updates (by an order of magnitude in
performance).
($alpha = $string_in) =~ tr/A-Za-z//cd;
($numeric = $string_in) =~ tr/0-9//cd;
Note, however, that the first operation is not locale-specific.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Jul 2000 19:36:06 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: New to perl, need help
Message-Id: <8kihb6$6b7$4@216.155.32.201>
In article <396AE74C.1AE0BBE6@orga.com>, Ulrich Ackermann <uackermann@orga.com>
wrote:
| #!/usr/local/bin/perl -w
| use strict;
|
| print "Input a number: ";
| chomp (my $number = <STDIN>);
| print "Result: ", fibonacci($number + 1), "\n";
|
| sub fibonacci {
| my $number = shift;
| return 1 if $number == 1;
| return 0 if $number == 0;
| return fibonacci($number - 1) + fibonacci($number - 2);
| }
pshew.. works, but gets darned slow around 25 and up -- anyone know of any slick
ways to make this sort of thing run faster? (just out of curiosity -- I've seen
you guys turn some complex pieces of code into around 15 chars :)
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: 12 Jul 2000 14:48:56 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: New to perl, need help
Message-Id: <87g0pfb047.fsf@limey.hpcc.uh.edu>
>> On 12 Jul 2000 19:36:06 GMT,
>> The WebDragon <nospam@nospam.com> said:
> In article <396AE74C.1AE0BBE6@orga.com>, Ulrich
> Ackermann <uackermann@orga.com> wrote:
> [ fibo code ]
> pshew.. works, but gets darned slow around 25 and up --
> anyone know of any slick ways to make this sort of thing
> run faster? (just out of curiosity -- I've seen you guys
> turn some complex pieces of code into around 15 chars :)
perldoc Memoize, e.g.
sub fib {
my $n = shift;
return 1 if $n == 1;
return 1 if $n == 2;
fib($n - 1) + fib($n - 2);
}
use Memoize;
memoize('fib');
for ( 1 .. 40 ) {
print fib($_), "\n";
}
TIMTOWTDI
hth
t
--
"With $10,000, we'd be millionaires!"
Homer Simpson
------------------------------
Date: Wed, 12 Jul 2000 19:50:20 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: New to perl, need help
Message-Id: <x73dlfku11.fsf@home.sysarch.com>
>>>>> "TW" == The WebDragon <nospam@nospam.com> writes:
TW> | sub fibonacci {
TW> | my $number = shift;
TW> | return 1 if $number == 1;
TW> | return 0 if $number == 0;
TW> | return fibonacci($number - 1) + fibonacci($number - 2);
TW> | }
TW> pshew.. works, but gets darned slow around 25 and up -- anyone
TW> know of any slick ways to make this sort of thing run faster?
TW> (just out of curiosity -- I've seen you guys turn some complex
TW> pieces of code into around 15 chars :)
unroll it into a loop. fib is easy to define in both recursive and loop
ways but the loop one is much faster.
perl -le '$n=shift; $f1=0;$f2=1; ($f1,$f2)=($f2,$f1+$f2), print $f1 while --$n' 10
1
1
2
3
5
8
13
21
34
golf anyone?
it can be shortened a bit like this by removing the init code:
perl -le '$n=shift;($f1,$f2)=($f2,$f1+$f2||1), print $f1 while --$n' 10
but that prints a leading blank line.
also shift can be turned into pop, f1 and f2 can be made single letters,
etc.
another trick is to use memoize if you want to speed up the recursive
(or even the loop) one at the expense of the ram used for the cache.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 12 Jul 2000 12:56:16 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: New to perl, need help
Message-Id: <m11z0zqg0v.fsf@halfdome.holdit.com>
>>>>> "WebDrago" == The WebDragon <nospam@nospam.com> writes:
WebDrago> In article <396AE74C.1AE0BBE6@orga.com>, Ulrich Ackermann <uackermann@orga.com>
WebDrago> wrote:
WebDrago> | #!/usr/local/bin/perl -w
WebDrago> | use strict;
WebDrago> |
WebDrago> | print "Input a number: ";
WebDrago> | chomp (my $number = <STDIN>);
WebDrago> | print "Result: ", fibonacci($number + 1), "\n";
WebDrago> |
WebDrago> | sub fibonacci {
WebDrago> | my $number = shift;
WebDrago> | return 1 if $number == 1;
WebDrago> | return 0 if $number == 0;
WebDrago> | return fibonacci($number - 1) + fibonacci($number - 2);
WebDrago> | }
WebDrago> pshew.. works, but gets darned slow around 25 and up --
WebDrago> anyone know of any slick ways to make this sort of thing run
WebDrago> faster? (just out of curiosity -- I've seen you guys turn
WebDrago> some complex pieces of code into around 15 chars :)
From the CPAN, get and install "Memoize". Then add to your program:
use Memoize;
memoize('fibonacci');
I bet it'll run tons faster after that. This is a classic function
that helps to be memoized.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 12 Jul 2000 20:22:28 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: New to perl, need help
Message-Id: <7an1jnjdyx.fsf@merlin.hyperchip.com>
Uri Guttman <uri@sysarch.com> writes:
> perl -le '$n=shift; $f1=0;$f2=1; ($f1,$f2)=($f2,$f1+$f2),
print $f1 while --$n' 10
> golf anyone?
Well, the obvious (but you already knew that):
s/shift/pop/;
> it can be shortened a bit like this by removing the init code:
> perl -le '$n=shift;($f1,$f2)=($f2,$f1+$f2||1), print $f1 while --$n' 10
If you don't care about warnings, then we can cheat a little:
perl -wle '($*,$^W)=($^W,$^W+$*),print$*for 0..pop' 10
--Ala
------------------------------
Date: Wed, 12 Jul 2000 13:34:55 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: New to perl, need help
Message-Id: <MPG.13d67646f3e7fb1298abc2@nntp.hpl.hp.com>
In article <m11z0zqg0v.fsf@halfdome.holdit.com> on 12 Jul 2000 12:56:16
-0700, Randal L. Schwartz <merlyn@stonehenge.com> says...
...
> From the CPAN, get and install "Memoize". Then add to your program:
>
> use Memoize;
> memoize('fibonacci');
>
> I bet it'll run tons faster after that. This is a classic function
> that helps to be memoized.
Indeed, but as so often, a module isn't needed to implement one line of
code. All it is is the familiar Orkish Maneuver.
#!/usr/bin/perl -w
use strict;
{ my %fib;
sub fibonacci {
my $number = shift;
$fib{$number} ||= $number < 2 ? $number :
fibonacci($number - 1) + fibonacci($number - 2)
} }
print fibonacci($_), "\n" for 0 .. 15;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 12 Jul 2000 21:28:29 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Odd problem with qx in ActivePerl
Message-Id: <schpmssaem5kqbi724fmcdf0eh24b4dcce@4ax.com>
bowp@my-deja.com wrote:
>From what I can see, the data I want to
>capture's disappearing off to STDERR.
Then redirect STDERR to a file, to start with.
open STDERR, ">stderr.txt";
my $ignore = qx(perl -e "oops this won't work");
close STDERR;
open FILE, "stderr.txt";
print "Reading:\"", <FILE>, "\"\n";
-->
Reading:"Can't locate object method "t" via package "won::t" at
-e line 1.
"
--
Bart.
------------------------------
Date: Wed, 12 Jul 2000 14:05:09 -0700
From: deno <jdNOjdSPAM@syncon.ie.invalid>
Subject: PRINTing " "" "
Message-Id: <1365619e.b93325a7@usw-ex0105-036.remarq.com>
Does anyone know how to make PRINT print an embedded " symbol?
I have lines which contain " which must be printed out.
EG
print "$company "some_text" more text" ; and so on.
Thanks IA.
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Wed, 12 Jul 2000 17:08:01 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: PRINTing " "" "
Message-Id: <396CDE31.AC65CDAB@attglobal.net>
deno wrote:
>
> Does anyone know how to make PRINT print an embedded " symbol?
> I have lines which contain " which must be printed out.
>
> print "$company "some_text" more text" ; and so on.
print "$company \"some_text\" more text"; #escape the "
-or -
print qq{$company "some_text" more text}; #different delimiter
Read the perlop manpage under heading "Quote and Quote like operators"
------------------------------
Date: Wed, 12 Jul 2000 14:16:00 -0700
From: deno <jdNOjdSPAM@syncon.ie.invalid>
Subject: Re: PRINTing " "" "
Message-Id: <2ef35294.bc076b53@usw-ex0105-036.remarq.com>
Thats brillant
Thanks
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Wed, 12 Jul 2000 22:01:15 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: PRINTing " "" "
Message-Id: <x7zonnj9ed.fsf@home.sysarch.com>
>>>>> "DS" == Drew Simonis <care227@attglobal.net> writes:
DS> deno wrote:
>>
>> Does anyone know how to make PRINT print an embedded " symbol?
>> I have lines which contain " which must be printed out.
>>
>> print "$company "some_text" more text" ; and so on.
DS> print "$company \"some_text\" more text"; #escape the "
please don't ever show that style of escaping quotes. i hate seeing it.
one solution is to use single quotes around the internal text. i have
mentioned this to some newbies and they were floored! DUH! if all you
are doing is highlighting something, then internal single quotes look fine.
and of course for those multiple print calls with html and double quoted
hrefs, here docs are the best way. just tell that to matt and his silly
minions!
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Wed, 12 Jul 2000 20:50:45 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Raise Exception when failure occurs ??
Message-Id: <m6fpmssml207keuqig7kmo27dnaubueoo3@4ax.com>
Ed Bras wrote:
> I know eval, but is that THE proper way to do it ??
eval BLOCK, yes.
--
Bart.
------------------------------
Date: Wed, 12 Jul 2000 20:06:49 GMT
From: kiran_mamidi@my-deja.com
Subject: Reading a line into variables: Question
Message-Id: <8kij4b$2f0$1@nnrp1.deja.com>
Hi,
I am very new to PERL scripts. I appreciate
if someone could help me with following.
How can read a line from a file.
The lines have values separated by commas.
Example of the file:
DF, 23, 99, 105D, K
DF, 24, 99, 105D, A
DF, 25, 99, 105D, R
I need to read each line and then each line into
different variables for a comparision (which I have gotten to that point
yet in my code....)
I need be able to read each line and then assign
$a = DF
$b = 23
$c = 99
$d = 105D
$e = K
Repeat this for each line.
Please see the code I am working on below. I can not figure out
how to read $_ into separate variables. In the file af each line can
have many values separated by commas.
#!/usr/local/bin/perl -w
open(AF, "/home/me/af");
while(<AF>) {
chomp;
print "$_\n";
}
close (AF);
Thanks in advance
Kiran
~
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 12 Jul 2000 16:32:30 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Reading a line into variables: Question
Message-Id: <396CD5DE.5D17464E@attglobal.net>
kiran_mamidi@my-deja.com wrote:
>
> Hi,
> I am very new to PERL scripts. I appreciate
> if someone could help me with following.
>
> How can read a line from a file.
> The lines have values separated by commas.
>
> Example of the file:
> DF, 23, 99, 105D, K
> DF, 24, 99, 105D, A
> DF, 25, 99, 105D, R
>
> I need to read each line and then each line into
> different variables for a comparision (which I have gotten to that point
> yet in my code....)
>
> I need be able to read each line and then assign
> $a = DF
> $b = 23
> $c = 99
> $d = 105D
> $e = K
>
> Repeat this for each line.
>
> Please see the code I am working on below. I can not figure out
> how to read $_ into separate variables. In the file af each line can
> have many values separated by commas.
Actually, they are seperated by a comma followed by a space in your
example.
#!/usr/local/bin/perl -w
use strict;
open AF, "/home/me/af" or die "Can't open: $!\n"; #always check!
while(<AF>)
{
chomp;
my ($a, $b, $c, $d, $e) = split /, /;
# do something with them now or they will be clobbered
}
close (AF);
------------------------------
Date: Wed, 12 Jul 2000 20:41:12 GMT
From: timhood@bigfoot.com
Subject: Re: Reading a line into variables: Question
Message-Id: <8kil55$3v4$1@nnrp1.deja.com>
In article <8kij4b$2f0$1@nnrp1.deja.com>,
kiran_mamidi@my-deja.com wrote:
> Hi,
> I am very new to PERL scripts. I appreciate
> if someone could help me with following.
>
> How can read a line from a file.
> The lines have values separated by commas.
>
> Example of the file:
> DF, 23, 99, 105D, K
> DF, 24, 99, 105D, A
> DF, 25, 99, 105D, R
>
> I need to read each line and then each line into
> different variables for a comparision (which I have gotten to that
point
> yet in my code....)
>
> I need be able to read each line and then assign
> $a = DF
> $b = 23
> $c = 99
> $d = 105D
> $e = K
>
> Repeat this for each line.
>
> Please see the code I am working on below. I can not figure out
> how to read $_ into separate variables. In the file af each line can
> have many values separated by commas.
>
> #!/usr/local/bin/perl -w
> open(AF, "/home/me/af");
> while(<AF>) {
> chomp;
> print "$_\n";
> }
You were close. Just put this in your while loop:
($a, $b, $c, $d, $e) = split /,/;
or, for a different or varying number of fields, you can
@fields = split /,/;
> close (AF);
>
> Thanks in advance
> Kiran
>
> ~
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 V9 Issue 3642
**************************************