[17776] in Perl-Users-Digest
Perl-Users Digest, Issue: 5196 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 25 18:05:26 2000
Date: Mon, 25 Dec 2000 15:05:08 -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: <977785507-v9-i5196@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 25 Dec 2000 Volume: 9 Number: 5196
Today's topics:
Re: convert string to command? (Tad McClellan)
Re: Copy data from outside page (Tad McClellan)
Error Message with Perl Code <edd@texscene.com>
Re: Error Message with Perl Code (Garry Williams)
Re: Get width/height of JPEG with perl? <waltman@netaxs.com>
Re: Get width/height of JPEG with perl? <you.will.always.find.him.in.the.kitchen@parties>
Re: list first n lines of matching paragraphs <monty@primenet.com>
Re: making unique list of words matching a pattern (Tad McClellan)
Re: making unique list of words matching a pattern (Ben Okopnik)
Re: making unique list of words matching a pattern (Ben Okopnik)
Re: making unique list of words matching a pattern (Garry Williams)
Re: making unique list of words matching a pattern <wescott@conterra.com>
Re: making unique list of words matching a pattern <uri@sysarch.com>
Re: making unique list of words matching a pattern (Abigail)
newbie randomize question <studdstr@qwest.net>
Re: newbie randomize question <timallen449@my-deja.com>
Re: newbie randomize question <jeffp@crusoe.net>
Parsing <SiStie@nuclear-network.de>
Re: Parsing (Garry Williams)
Re: Parsing (Abigail)
Perl and PDF manipulation andre_amiri@yahoo.com
several questions about globals <news@#nospam#althepal.com>
Re: several questions about globals (Garry Williams)
Re: several questions about globals <iltzu@sci.invalid>
Syntax for "eq" and "||" <paul_wasilkoff@ucg.org>
Re: Syntax for "eq" and "||" <tony_curtis32@yahoo.com>
Re: vec seems to need a tmp in my .pm file?? (Richard Zilavec)
Re: Where can I get CRYPT for DOS/WIN? (Tad McClellan)
Re: yet another question: is ' more efficient than "? <iltzu@sci.invalid>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 25 Dec 2000 09:17:03 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: convert string to command?
Message-Id: <slrn94elmv.98d.tadmc@magna.metronet.com>
Studio 51 <leekembel@hotmail.com> wrote:
>What I'm trying to do is read a small list of categories into memory.
>Categories have subcategories, which have subcategories, etc... I have each
>category as a key in one gigantic hash full of hashes,
Can we then assume that you have looked at the standard Perl docs
that are germane to multi-level data structures?
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
>with the value for
>the key being all the subcategories within that category. The problem is
>that I have to refer to a bunch of nested hashes when the names are created
>dynamically. So Sports > Football > Equipment would be
>$cat{'Sports'}{'Football'}{'Equipment'}. But I'm having trouble finding a
>way to refer to it as such because all the names depend on other data I read
>in from a database.
I'm not seeing what the problem is. Can you eventually get to
having all of the keys in variables? If so then:
$cat{$level1}{$level2}{$level3}
>I tried using eval(), and it worked,.. sort of.
Warning Will Robinson!
eval() is dangerous and should be avoided when possible.
It is very often possible to avoid its use.
>To help explain a little better,
I, at least, need an even better explanation... :-(
I suspect that the root difficulty is the data structure you
have chosen. It is likely that there is a more convenient
representation, but I'm not clear enough on what you really
need to be able to offer an alternative.
>this is what I mean:
Ask the machine to give you as much help as it can!
Enable warnings.
Use strictures.
#!/usr/bin/perl -w
use strict;
If you are working with multi-level data structures, know and use
the Data::Dumper module for debugging:
use Data::Dumper;
print Dumper @arrayref;
>foreach $rowref (@arrayref) {
> foreach $row (@$rowref) {
It helps us help you if we have code *that we can run* that illustrates
the problem that you are having.
But we don't (hint).
That, coupled with no warnings and strictures, makes further
attempts at helping you an unproductive use of time (i.e.
lots of readers will stop reading at this point).
You might want to consider fixing those 3 things and posting again.
> $name = @$row[0]; #the category name, i.e. Equipment
^^^^
<hot-button>
Folks saying exactly the opposite of what they thought they said
sets me to pointing out their inversion.
"i.e. vs. e.g." is one of the two that launches me (the other
is "irregardless vs. regardless").
I am sure what you wanted to say was "for example" (e.g.).
But you didn't say that. You said "that is" (i.e.).
$name = @$row[0]; #the category name, that is, Equipment
You have said that $name will _always_ be 'Equipment'.
That can't be what you wanted to say...
</hot-button>
> $path = @$row[1]; #path to this category, i.e. /Sports/Football/
^
^
I figure you are trying to dereference a reference to an array there?
Do you really want to evaluate the array in scalar context?
> eval ( "\$cat".$dirref."{'auctions'} = {"auctions" => $auctions}" );
^^^^^^^
It looks to me like you have a variable part of the *name* of
the hash, implying that there is more than one such hash.
I thought you said above that you had _one_ gigantic hash?
That (adding another "level" of hash) is a classic way of
avoiding evil symbolic references.
And it doesn't even compile, the quoting is messed up!
It appears that we don't even have your real code here!
>#This is the line that seems to be the problem?
You betcha it is!
Using eval() and "Symbolic references" together is a double-whammy
Very Bad Thing.
You should be able to get what you want without either of those
high-potential-for-introducing-bugs features.
Since everybody with a lick of sense always runs with strictures
turned on, you won't be allowed to even _aim_ the gun at your foot,
avoiding the potential for experiencing a painful figurative wound.
To get a feel for the gore and violence that can be the result
of using symrefs, see:
http://www.plover.com/~mjd/perl/varvarname.html
http://www.plover.com/~mjd/perl/varvarname2.html
http://www.plover.com/~mjd/perl/varvarname3.html
>What could be causing this?
I dunno. I don't have code that duplicates the problem, so I
cannot attack fixing the code.
>Or are
>there better ways to read this category structure into memory?
This seems likely in the extreme...
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 25 Dec 2000 07:14:31 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Copy data from outside page
Message-Id: <slrn94eeh7.98d.tadmc@magna.metronet.com>
Victor <a@a> wrote:
>
>Could anyone teach me how to use cgi to copy information/data from an
^^^^^^^
>outside html page.
I'm not going to answer the question you asked.
I'll show you how to do it *without* CGI though:
use LWP::Simple;
my $weather = get 'http://weather.yahoo.com/forecast/Hong_Kong_CI_c.html';
The LWP module is part of the 'libwww' bundle at CPAN.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 25 Dec 2000 20:53:15 -0000
From: "Edd" <edd@texscene.com>
Subject: Error Message with Perl Code
Message-Id: <3a47b199@news-uk.onetel.net.uk>
When I run my perl code which sends email, I get the following error
message. What does this message mean? Can somebody help please.
Name "main::to" used only once: possible typo at line:
$to="info\@testing.com";
Name "main::to" used only once: possible typo at line:
$from="info\@testing.com";
The whole of the code is as below: ---------------
#!/usr/bin/perl -w
&Parse_Form_amail;
print $query->header();
use CGI qw/:standard/;
$to = "info\@testing.com";
open (MAIL, "|/usr/sbin/sendmail -t") || print "<p>Not opening";
print MAIL "To: $to\n From: $from\n";
print MAIL "$comments\n";
close (MAIL);
print "thank you";
#---line20------------ Subroutine To Parse Form a1 ----------------------
sub Parse_Form_amail {
use CGI;
$query = CGI::new();
$from=$query->param("from");
$comments=$query->param("comments");
}
1;
------------------------------
Date: Mon, 25 Dec 2000 21:41:12 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Error Message with Perl Code
Message-Id: <Y9P16.1315$Kk5.60365@eagle.america.net>
On Mon, 25 Dec 2000 20:53:15 -0000, Edd <edd@texscene.com> wrote:
>When I run my perl code which sends email, I get the following error
>message. What does this message mean? Can somebody help please.
>
>
>Name "main::to" used only once: possible typo at line:
>$to="info\@testing.com";
>Name "main::to" used only once: possible typo at line:
>$from="info\@testing.com";
Maybe you should cut and paste the actual warning messages.
>The whole of the code is as below: ---------------
>
>#!/usr/bin/perl -w
You should use taint checking (option -T) for CGI programs. Read the
"Where can I learn about CGI or Web programming in Perl?" section in
the perlfaq3 manual page (especially http://www.w3.org/Security/Faq/).
You should also use strict.
>&Parse_Form_amail;
>
>print $query->header();
>use CGI qw/:standard/;
>$to = "info\@testing.com";
>open (MAIL, "|/usr/sbin/sendmail -t") || print "<p>Not opening";
Although you print an error message (good), you did not include the $!
variable (bad). Perl can tell you _why_ the open failed. Also
execution will continue without a validly opened file handle.
See the CGI::Carp manual page for a better way to get error messages
reported to the browser.
>print MAIL "To: $to\n From: $from\n";
>print MAIL "$comments\n";
You did not separate the body of your message from the headers. You
also put a space in front of your From: header thus making it a part
of your To: header.
(Did you cut and paste?)
You should read the perlfaq9 manual page, "How do I send mail?".
>close (MAIL);
You should *always* check the result of closing a pipe (and print the
value of $!, if it fails). This is where most errors will be
reported.
>print "thank you";
>
>
>#---line20------------ Subroutine To Parse Form a1 ----------------------
>
>sub Parse_Form_amail {
>
>use CGI;
>$query = CGI::new();
>
>$from=$query->param("from");
>$comments=$query->param("comments");
>}
>1;
This code does *not* produce the warnings you report above.
(Did you cut and paste?)
--
Garry Williams
------------------------------
Date: 25 Dec 2000 13:29:48 -0500
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: Get width/height of JPEG with perl?
Message-Id: <m3g0jcs6ar.fsf@netaxs.com>
"Studio 51" <leekembel@hotmail.com> writes:
> Anyone know if you can get the width/height of a JPEG with perl? I've
> managed to find a script that gets the dimensions of a GIF, but even more
> than source code I'd like to find a tutorial, guide, or some info on how to
> do it, especially with JPEGs.
Try the Image::Size module, available on CPAN.
------------------------------
Date: Tue, 26 Dec 2000 08:07:26 +1300
From: "Tintin" <you.will.always.find.him.in.the.kitchen@parties>
Subject: Re: Get width/height of JPEG with perl?
Message-Id: <977771380.527605@shelley.paradise.net.nz>
"Studio 51" <leekembel@hotmail.com> wrote in message
news:iED16.150688$_5.33209707@news4.rdc1.on.home.com...
> Anyone know if you can get the width/height of a JPEG with perl? I've
> managed to find a script that gets the dimensions of a GIF, but even more
> than source code I'd like to find a tutorial, guide, or some info on how
to
> do it, especially with JPEGs.
Grab Image::Size from CPAN.
use Image::Size
my ($x,$y) = imgsize('logo.jpg');
You can look at the code if you want to know how the module does it stuff.
------------------------------
Date: 25 Dec 2000 17:20:50 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: list first n lines of matching paragraphs
Message-Id: <927vli$ip8$1@nnrp2.phx.gblx.net>
Vivekvr <vivekvr@aol.com> wrote:
> Has anyone written a Perl script to list the first n (or all, if
> no number specified) lines of all the paragraphs in a file which
> contain a specified regular expression. Paragraphs are separated
> by blank lines (perhaps spaces or tabs, but no alphanumeric
> characters).
>
> I have a list of references with abstracts, separated by spaces,
> and I would like, for example to list the first 4 lines of all
> references containing "Smith".
Carving up multiline records is trivial in both awk and Perl:
$ cat records
Adam Smith
1234 Wall St., Apt. 5C
New York, NY 10021
212 555-4321
David W. Copperfield
221 Dickens Lane
Monterey, CA 93940
408 555-0041
work phone 408 555-6532
Mary, birthday January 30
Canadian Consulate
555 Fifth Ave
New York, NY
212 586-2400
$ awk 'BEGIN { RS = ""; FS = "\n" } /Smith/ { print $1 }' records
Adam Smith
$ perl -ne 'BEGIN { $/ = ""; $\ = "\n" }
> print +(split /\n/)[0] if /Smith/' records
Adam Smith
$ awk 'BEGIN { RS = ""; FS = "\n" } /New York/ { print $1, $2 }' records
Adam Smith 1234 Wall St., Apt. 5C
Canadian Consulate 555 Fifth Ave
$ perl -ne 'BEGIN { $/ = ""; $\ = "\n"; $, = " " }
> print +(split /\n/)[0,1] if /New York/' records
Adam Smith 1234 Wall St., Apt. 5C
Canadian Consulate 555 Fifth Ave
$
[This example data comes from p. 83 of _The AWK Programming Language_
(ISBN 0-201-07981-X).]
Adapting the example scripts above to allow the user to specify
the regular expression pattern and the list of lines to print is
left as a holiday exercise for the reader. Merry Christmas!
--
Jim Monty
monty@primenet.com
Tempe, Arizona USA
------------------------------
Date: Mon, 25 Dec 2000 07:00:43 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: making unique list of words matching a pattern
Message-Id: <slrn94ednb.98d.tadmc@magna.metronet.com>
Ben Okopnik <fuzzybear@pocketmail.com> wrote:
>The ancient archives of Mon, 25 Dec 2000 03:05:21 GMT showed
>Bob Walton of comp.lang.perl.misc speaking thus:
>>Vivekvr wrote:
>>>
>>> to list the unique words in a file that match a regular expression?
^^^^^^
^^^^^^
>OK, I've just got to ask: what's wrong with a plain 'match and print'?
It does not meet the specification.
>am I missing something?
A careful read of the problem specification?
:-)
[ Though the OP's sample data was deficient 'cause it did not
provide any duplicated entries.
]
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 25 Dec 2000 18:16:09 GMT
From: fuzzybear@pocketmail.com (Ben Okopnik)
Subject: Re: making unique list of words matching a pattern
Message-Id: <slrn94f3ts.rfb.fuzzybear@Odin.Thor>
The ancient archives of 25 Dec 2000 11:55:44 GMT showed
Abigail of comp.lang.perl.misc speaking thus:
>Ben Okopnik (fuzzybear@pocketmail.com) wrote on MMDCLXXIII September
>MCMXCIII in <URL:news:slrn94dnk2.q56.fuzzybear@Odin.Thor>:
>@@
>@@ OK, I've just got to ask: what's wrong with a plain 'match and print'?
>@@
>@@ perl -040 -nwe 'print "$&\n" if /\b\w*\.cpp\b/;'
>@@
>@@ or, if you prefer -
>@@
>@@ $/=" ";
>@@ while (<>) { print "$&\n" if /\b\w*\.cpp\b/; }
>
>Golf, anyone?
Odin~$> perldoc Abigail::golf
No documentation found for "Abigail::golf"
Odin~$>
Rats, it's undocumented.
#!/usr/bin/perl -w
use strict;
use diagnostics;
use Abigail::reference;
print $ab_ref->golf;
<Grin> Sorry, I miss your meaning.
> perl -walne'map/\.cpp$/&&print,@F' file
Whew. Left me behind; I'm just starting to understand 'map', and that went
clean over...
Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
If people are good only because they fear punishment, and hope for reward,
then we are a sorry lot indeed. -- Albert Einstein
------------------------------
Date: 25 Dec 2000 18:19:37 GMT
From: fuzzybear@pocketmail.com (Ben Okopnik)
Subject: Re: making unique list of words matching a pattern
Message-Id: <slrn94f44c.rfb.fuzzybear@Odin.Thor>
The ancient archives of Mon, 25 Dec 2000 07:00:43 -0500 showed
Tad McClellan of comp.lang.perl.misc speaking thus:
>Ben Okopnik <fuzzybear@pocketmail.com> wrote:
>>The ancient archives of Mon, 25 Dec 2000 03:05:21 GMT showed
>>Bob Walton of comp.lang.perl.misc speaking thus:
>>>Vivekvr wrote:
>>>>
>
>>>> to list the unique words in a file that match a regular expression?
> ^^^^^^
> ^^^^^^
>
>>OK, I've just got to ask: what's wrong with a plain 'match and print'?
>
>
>It does not meet the specification.
<Slapping forehead> Duh. I suspected it was something like that; that's
why I asked. Thanks, Tad.
Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Men are rewarded or punished not for what they do but for how their acts
are defined. That is why men are more interested in better justifying
themselves than in better behaving themselves. -- Thomas S. Szasz
------------------------------
Date: Mon, 25 Dec 2000 19:37:44 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: making unique list of words matching a pattern
Message-Id: <cmN16.1300$Kk5.59723@eagle.america.net>
On 25 Dec 2000 14:39:25 GMT, Vivekvr <vivekvr@aol.com> wrote:
>Thanks for the help. I found that
[Missing attribution for Abigail's post]
>>perl -walne 'map/\.cpp$/&&print,@F' file
>
>does not work on my Windows 2000 machine, but it does when the
>single quotes are replaced by double quotes (change ' to ").
Yup. And it's documented in the manual. From the perlrun manual
page:
#! and quoting on non-Unix systems
...
Command-interpreters on non-Unix systems have rather
different ideas on quoting than Unix shells. You'll need to
learn the special characters in your command-interpreter
(`*', `\' and `"' are common) and how to protect whitespace
and these characters to run one-liners (see -e below).
--> On some systems, you may have to change single-quotes to
double ones, which you must not do on Unix or Plan9 systems.
You might also have to change a single % to a %%.
Of course you could also run the bash shell on Windows and be much
happier.
--
Garry Williams
------------------------------
Date: Mon, 25 Dec 2000 19:53:46 GMT
From: Mike Wescott <wescott@conterra.com>
Subject: Re: making unique list of words matching a pattern
Message-Id: <os4rzsi8f8.fsf@eriadne.sc.rr.com>
fuzzybear@pocketmail.com (Ben Okopnik) writes:
> Bob Walton wrote:
>> Vivekvr wrote:
>>> Has anyone written a Perl (or sed or awk etc) program
>>> to list the unique words in a file that match a regular expression?
>>> The words are separated by spaces.
>>> For example, in the input
>>> boy cat girl
>>> foo.c boo.cpp goo.c hoo.cpp
>>> I want to list strings matching "*.cpp", which would be
>>> boo.cpp
>>> hoo.cpp
> Bob Walton of comp.lang.perl.misc speaking thus:
>> How about:
>> @hash{(join '',<>)=~/\b([^ ]*\.cpp)\b/gs}=1;
>> @matches=keys %hash;
> OK, I've just got to ask: what's wrong with a plain 'match and print'?
The stated requirement was for the *unique* words. This is usually taken
to mean that the result should contain no duplicates.
On the other hand, the match and print approach does have some merit.
I'd use something like this:
tr -s '[:space:]' '\n' | grep '\.cpp$' | sort -u
> perl -040 -nwe 'print "$&\n" if /\b\w*\.cpp\b/;'
This has problems with matching words that start a line (other than the
first line). And might be more restrictive than desired by not allowing
non-alphanumerics in the filename.
--
Mike Wescott
wescott@conterra.com
------------------------------
Date: Mon, 25 Dec 2000 22:08:53 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: making unique list of words matching a pattern
Message-Id: <x7vgs8b1ca.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@foad.org> writes:
A> Golf, anyone?
A> perl -walne'map/\.cpp$/&&print,@F' file
tie score with:
perl -walne'/\.cpp$/&&print for@F' file
and no map in void context which i know you love. :)
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: 25 Dec 2000 22:19:35 GMT
From: abigail@foad.org (Abigail)
Subject: Re: making unique list of words matching a pattern
Message-Id: <slrn94fhvn.gbq.abigail@tsathoggua.rlyeh.net>
Uri Guttman (uri@sysarch.com) wrote on MMDCLXXIII September MCMXCIII in
<URL:news:x7vgs8b1ca.fsf@home.sysarch.com>:
<> >>>>> "A" == Abigail <abigail@foad.org> writes:
<>
<> A> Golf, anyone?
<>
<> A> perl -walne'map/\.cpp$/&&print,@F' file
<>
<> tie score with:
<>
<> perl -walne'/\.cpp$/&&print for@F' file
<>
<> and no map in void context which i know you love. :)
And here's a version that only prints uniques:
$ perl -walne'map$_{$_}++||/\.cpp$/&&print,@F' file
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
------------------------------
Date: Mon, 25 Dec 2000 11:27:16 -0800
From: Jimmy <studdstr@qwest.net>
Subject: newbie randomize question
Message-Id: <3A479F93.35215236@qwest.net>
I am looking to display the lines from a file, in a random order. I have
not found anything on how I should do this. Should i use an array, a
hash, a _____ ??
Could someone point me in the right direction?
Thanx in Advance
Jimmy
------------------------------
Date: Mon, 25 Dec 2000 21:20:28 GMT
From: tim allen <timallen449@my-deja.com>
Subject: Re: newbie randomize question
Message-Id: <928dmq$5du$1@nnrp1.deja.com>
In article <3A479F93.35215236@qwest.net>,
Jimmy <studdstr@qwest.net> wrote:
> I am looking to display the lines from a file, in a random order.
Looks like your idea of using an array is a good one. The Perl Cookbook
(Tom Christiansen & Nathan Torkinton) lists this on p. 286, explaining
to 1) read the lines into an array, 2) shuffle the array, and 3) write
the lines back out.
I don't know if I'm allowed by copyright to send this code out on this
forum. Is that kosher? The book has a lot of answers to questions
like this, code included.
I hope that helps... sorry I couldn't send the code. Maybe if Messrs
Christiansen or Torkington themselves respond and say it's okay, I can
do it) good luck! -tim allen
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Mon, 25 Dec 2000 16:36:16 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: newbie randomize question
Message-Id: <Pine.GSO.4.21.0012251632320.25445-100000@crusoe.crusoe.net>
[posted & mailed(?)]
On Dec 25, tim allen said:
>Looks like your idea of using an array is a good one. The Perl Cookbook
>(Tom Christiansen & Nathan Torkinton) lists this on p. 286, explaining
>to 1) read the lines into an array, 2) shuffle the array, and 3) write
>the lines back out.
>
>I don't know if I'm allowed by copyright to send this code out on this
>forum. Is that kosher? The book has a lot of answers to questions
>like this, code included.
It is allowed (especially since a lot of the code in the cookbook can be
found in other places, like the FAQ). To not be allowed to use code from
a book created expressly for the purpose of providing code to use in
certain situations would be silly. And since much code is merely an
implementation of an algorithm in a given language, I don't think you
could claim ownership to a bit of Perl code that performs a Fisher-Yates
shuffle on an array.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
PerlMonks - An Online Perl Community http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
------------------------------
Date: Mon, 25 Dec 2000 22:23:54 +0100
From: Simon Stiefel <SiStie@nuclear-network.de>
Subject: Parsing
Message-Id: <Pine.LNX.4.31.0012252154170.3664-100000@server.stiefel.priv>
Hi,
I want to parse the output of "finger".
The output could be something like this:
root root 1 1 Mon 20:10
root root 2 - Mon 20:10
sistie Simon Stiefel *3 - Mon 20:12
^^^^^^^^^^|^^^^^^^^^^^^^^^^^^^^|^^^^^^^^^^^^|^^^^^|^^^^^^^^^^
$1=09=09 $2=09=09 $3=09 $4 $5
Now, I want to parse those "areas" and save them in different variables
(see above).
So, uhm, does anybody have an idea how to realize that? =3D)
And, excuse me about my terrible english...
Mit freundlichen Gr=FC=DFen,=09.~.=09Open Minds.
with best regards=09 /V\ =09=09Open Sources.
=09=09=09 // \\=09=09=09Open Future!
Simon Stiefel=09=09 /( )\_ I N U X
=09=09=09 ^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.de | http://www.nuclear-network.de |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |
------------------------------
Date: Mon, 25 Dec 2000 22:02:55 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Parsing
Message-Id: <juP16.1317$Kk5.59577@eagle.america.net>
On Mon, 25 Dec 2000 22:23:54 +0100, Simon Stiefel
<SiStie@nuclear-network.de> wrote:
>I want to parse the output of "finger".
>The output could be something like this:
>
>root root 1 1 Mon 20:10
>root root 2 - Mon 20:10
>sistie Simon Stiefel *3 - Mon 20:12
>^^^^^^^^^^|^^^^^^^^^^^^^^^^^^^^|^^^^^^^^^^^^|^^^^^|^^^^^^^^^^
> $1 $2 $3 $4 $5
How about using unpack()? Or substr()?
(See the perlfaq5 manual page, "How can I manipulate
fixed-record-length files?" for an example.)
By the way, those variables above are read-only. You probably want to
choose different names.
>And, excuse me about my terrible english...
It's excellent! (Well, it's much better than my German :-)
--
Garry Williams
------------------------------
Date: 25 Dec 2000 22:07:40 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Parsing
Message-Id: <slrn94fh9c.gbq.abigail@tsathoggua.rlyeh.net>
Simon Stiefel (SiStie@nuclear-network.de) wrote on MMDCLXXIII September
MCMXCIII in <URL:news:Pine.LNX.4.31.0012252154170.3664-100000@server.stiefel.priv>:
// Hi,
//
// I want to parse the output of "finger".
// The output could be something like this:
//
// root root 1 1 Mon 20:10
// root root 2 - Mon 20:10
// sistie Simon Stiefel *3 - Mon 20:12
// ^^^^^^^^^^|^^^^^^^^^^^^^^^^^^^^|^^^^^^^^^^^^|^^^^^|^^^^^^^^^^
// $1 $2 $3 $4 $5
//
// Now, I want to parse those "areas" and save them in different variables
// (see above).
//
// So, uhm, does anybody have an idea how to realize that? =)
unpack
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Mon, 25 Dec 2000 22:37:22 GMT
From: andre_amiri@yahoo.com
Subject: Perl and PDF manipulation
Message-Id: <928i73$8el$1@nnrp1.deja.com>
I know there are quite a few modules for creating PDF files using Perl.
However, is there one for the manipulation/annotation of an existing
PDF file? Thanks.
Andre Amiri
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Mon, 25 Dec 2000 18:53:21 GMT
From: Alex Hart <news@#nospam#althepal.com>
Subject: several questions about globals
Message-Id: <BIM16.3255$1m.1600272@typhoon2.ba-dsg.net>
I'm trying to get around the closure problem caused by mod_perl. I'd
like to fully qualify the variables I'm using.
Does specifying a package with a variable automatically create a
global?? For instance, if in the middle of my code I say that $Xyz::temp
= 5;, is this a global variable now? I notice that even with 'use
strict' at the top of the code, using a variable like this in the middle
does not cause a warning. Why is this? is there such a thing as a fully
qualified lexical variable?
Is there a way to share variables with nested subroutines without
creating a global variable? I don't want to pass the variables as
arguments because there are too many?
Also, why are global variables so bad? is it a memory consideration? is
it just the possibility of doing something wroing with it?
I know it's a lot to ask. I appreciate your time. Thanks.
--
- Alex Hart
$j="592888088758319859281631592858792919873179698955";
$p="push\@_,";$c="chop(\$_)";$_="$p$p($c.$c)+19;eval;
+".$j;eval;%_=map{chr}reverse@_;foreach(sort+keys%_){print$_{$_}}
------------------------------
Date: Mon, 25 Dec 2000 21:01:54 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: several questions about globals
Message-Id: <6BO16.1311$Kk5.60334@eagle.america.net>
On Mon, 25 Dec 2000 18:53:21 GMT, Alex Hart
<news@#nospam#althepal.com> wrote:
>I'm trying to get around the closure problem caused by mod_perl.
I'm not sure what `the closure problem' is, but...
>I'd
>like to fully qualify the variables I'm using.
>
>Does specifying a package with a variable automatically create a
>global??
Uh, yes. That's _what_ a package variable is. It can be referred to
globally.
>For instance, if in the middle of my code I say that $Xyz::temp
>= 5;, is this a global variable now?
Yes. (Mentioning it in _any_ context is sufficient.)
>I notice that even with 'use
>strict' at the top of the code, using a variable like this in the middle
>does not cause a warning. Why is this?
This from the strict manual page:
`strict vars'
This generates a compile-time error if you access a
variable that wasn't declared via "our" or `use vars',
localized via `my()', or wasn't fully qualified.
^^^^^^^^^^^^^^^^^^^^^^^^^
>is there such a thing as a fully
>qualified lexical variable?
Doesn't make sense. If it's lexically scoped, it's not available
outside ... well, the lexical scope. You should read the "Private
Variables via my()" section of the perlsub manual page for a good
discussion of lexical scoping.
>Is there a way to share variables with nested subroutines without
^^^^^^^^^^^^^^^^^^^^^^^
>creating a global variable? I don't want to pass the variables as
>arguments because there are too many?
I'm not sure what you mean by `nested subroutines'. But if you want
to share variables in different _lexical scopes_, that requires a
package variable. (I suppose you could pass around a reference to a
lexical, but I don't think that's what you mean.)
You may want to use a hash instead of individual scalars.
But I suspect that you may have a more fundamental problem (or
challenge) involving your design.
>Also, why are global variables so bad? is it a memory consideration? is
>it just the possibility of doing something wroing with it?
It's not a memory problem. It's a "coupling" problem. One objective
in design is to reduce module coupling. Good design strives to hide
the details of implementation of functionality behind the function
interface; to limit communication between modules to the parameters
that are explicitly passed. When you define global data that
functions depend on, the action of the function can be affected by
code that did not call the function. You get "action at a distance".
It makes maintenance, testing and debugging harder. In the extreme,
it makes these things nearly impossible.
So it's a software engineering issue. Re-factor.
--
Garry Williams
------------------------------
Date: 25 Dec 2000 21:46:57 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: several questions about globals
Message-Id: <977780533.24943@itz.pp.sci.fi>
In article <BIM16.3255$1m.1600272@typhoon2.ba-dsg.net>, Alex Hart wrote:
>
>Is there a way to share variables with nested subroutines without
>creating a global variable? I don't want to pass the variables as
>arguments because there are too many?
Put the variables in a hash. Pass the hash around by reference.
If you put all the subroutines using the hash in their own package,
and bless the hash to that package, you now have a Perl object. If
your subroutines are mostly about manipulating the data in the hash,
this might make sense. Or it might not.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Mon, 25 Dec 2000 13:12:57 -0500
From: "Paul Wasilkoff" <paul_wasilkoff@ucg.org>
Subject: Syntax for "eq" and "||"
Message-Id: <t4f3jrbmsam0ef@corp.supernews.com>
I am trying to write a component in a script to act one in two ways. If
condition 1 is met action 1 is taken; if condition 2, then action 2.
In a web form I have a pull down country list; it the user selects Canada,
Austalia, the UK then action 1 is to be taken; for the US and all other
countries action 2 is taken.
How do I express this with the "eq" and "||" operators? Can I express them
like:
if ($in{'Contact_Country'} eq "Austalia" || "Canada" || "UK")
{
action 1
{
else
action 2
Or should I pack them into an array (since there are 24 countries in total
that need to go to action 1)?
------------------------------
Date: 25 Dec 2000 12:20:04 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Syntax for "eq" and "||"
Message-Id: <87hf3sbbxn.fsf@limey.hpcc.uh.edu>
>> On Mon, 25 Dec 2000 13:12:57 -0500,
>> "Paul Wasilkoff" <paul_wasilkoff@ucg.org> said:
> In a web form I have a pull down country list; it the user selects
> Canada, Austalia, the UK then action 1 is to be taken; for the US
> and all other countries action 2 is taken.
> How do I express this with the "eq" and "||" operators? Can I
> express them like:
> if ($in{'Contact_Country'} eq "Austalia" || "Canada" || "UK") {
^^^^^^^^
cgi-lib.pl alert? Time to move to CGI.pm ...
> action 1 { else action 2
A hash would be best here.
The keys are the countries requiring special action (or maybe their
digraph codes for brevity). The associated values are the actions.
You can use a defined() test to see if a special handler has been set
up for a country.
perldoc perldata
perldoc perldsc
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Mon, 25 Dec 2000 17:36:02 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: vec seems to need a tmp in my .pm file??
Message-Id: <3a478017.597716721@news.tcn.net>
On Fri, 22 Dec 2000 20:09:29 GMT, nobull@mail.com wrote:
>In article <3a447403.89454067@news.tcn.net>,
> rzilavec@tcn.net wrote:
>
>> $hash{$num} = pack("b*", "0" x $total);
>
>> vec($hash{$word}, $num, 1) = 1;
>
>You problem is that one line you refer to $hash{$num} and on the other
>$hash{word}
My apologies, that is just a typo in my post, I will be more careful
in the future when posting.
I have searched around but I am still not able to use vec directly
with dbm in my package, the swap variable seems to be required.
unless(defined $words{$word}) {
$bitstring = pack("b*", "0" x $self->{TOTALDOCS});
vec($bitstring, $count, 1) = 1;
$words{$word} = $bitstring;
} else {
$bitstring = $words{$word};
vec($bitstring, $count, 1) = 1;
$words{$word} = $bitstring;
}
--
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Mon, 25 Dec 2000 07:07:01 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Where can I get CRYPT for DOS/WIN?
Message-Id: <slrn94ee35.98d.tadmc@magna.metronet.com>
Studio 51 <leekembel@hotmail.com> wrote:
>"Tad McClellan" <tadmc@metronet.com> wrote in message
>news:slrn94dbmu.7vk.tadmc@magna.metronet.com...
>> Vitaly Tkachenko <virtualvat@yahoo.com> wrote:
>> >It just doesn't work correctly.
>> Yes it does.
>
>Just 30 minutes ago I was reading about how crypt() doesn't work properly in
>ActiveState Perl (windows).
Oops. I didn't check the Subject. Sorry.
My score file let me down again...
>I WISH I could find the page to show you
That's OK. I don't need to know about that platform anyway. :-)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 25 Dec 2000 21:35:20 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <977779153.22380@itz.pp.sci.fi>
In article <927p9p$oa0$1@nnrp1.deja.com>, timallen449@my-deja.com wrote:
>
>Thanks Ilmari. Something you said interested me a lot. I, too, would
>like to be able to see and compare the bytecode of two statements, as I
>agree with you that *that* would be the ultimate way of comparing two
>methods. How would I do that? Is there a FAQ I should read about
>this? Thank you very much. -tim
The B::Bytecode module can do this. You can get non-binary output
from it by specifying the -S option for it, but it's still rather
unreadable for most of us. If your interested in doing more than
simply comparing two expressions, you'll probably find the B::Deparse
module more useful:
$ perl -MO=Deparse -e \$_=\"foobar\"
-e syntax OK
$_ = 'foobar';
$ perl -MO=Deparse -e \$_=\'foobar\'
-e syntax OK
$_ = 'foobar';
Now, B::Deparse isn't perfect. I've encountered code that breaks it,
and at least one expression that changes semantics when it's deparsed.
But it is nonetheless a very useful tool.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
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 5196
**************************************