[22560] in Perl-Users-Digest
Perl-Users Digest, Issue: 4781 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 29 00:11:06 2003
Date: Fri, 28 Mar 2003 21:10:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 28 Mar 2003 Volume: 10 Number: 4781
Today's topics:
open fails with filename starting with space <vilmos@vilmos.org>
Re: open fails with filename starting with space (David Efflandt)
Re: open fails with filename starting with space <jurgenex@hotmail.com>
Re: open fails with filename starting with space <krahnj@acm.org>
Re: open fails with filename starting with space <goldbb2@earthlink.net>
Re: pattern matching <minceme@start.no>
Perl and Objects <mail@annuna.com>
Re: Perl and Objects <jkeen@concentric.net>
Re: Perl modules. <me@privacy.net>
Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
Re: Perl modules. (Tad McClellan)
Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
Please tell me I'm beginner <amiba128@sd6.so-net.ne.jp>
Re: Please tell me I'm beginner <abigail@abigail.nl>
Re: Please tell me I'm beginner <amiba128@sd6.so-net.ne.jp>
Re: Please tell me I'm beginner <jurgenex@hotmail.com>
Re: Please tell me I'm beginner <amiba128@sd6.so-net.ne.jp>
Re: Please tell me I'm beginner <jurgenex@hotmail.com>
Re: print out multi queries <goldbb2@earthlink.net>
Re: search and replace long hex string <krahnj@acm.org>
Re: search and replace long hex string <krahnj@acm.org>
Re: Sorting keys in a hash runs slower now. (Anno Siegel)
Re: Sorting keys in a hash runs slower now. <goldbb2@earthlink.net>
Re: Ugh. Better way to turn strings into trees. SOLUTIO <goldbb2@earthlink.net>
Re: why heredoc? was: Re: print here-documents question <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Mar 2003 18:50:06 -0800
From: Vilmos Soti <vilmos@vilmos.org>
Subject: open fails with filename starting with space
Message-Id: <87r88qubs1.fsf@localhost.localdomain>
Hello,
I was writing a program which traversed a directory structure
(~/GNUstep), and I found that open couldn't open a filename with
a leading space. Is there a simple way (not sysopen) around it?
Thanks, Vilmos
------------------------------
Date: Sat, 29 Mar 2003 03:15:05 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: open fails with filename starting with space
Message-Id: <slrnb8a3tp.gpt.efflandt@typhoon.xnet.com>
On 28 Mar 2003 18:50:06 -0800, Vilmos Soti <vilmos@vilmos.org> wrote:
> Hello,
>
> I was writing a program which traversed a directory structure
> (~/GNUstep), and I found that open couldn't open a filename with
> a leading space. Is there a simple way (not sysopen) around it?
Depending upon your OS and shell, you may need to escape any spaces or
literally include quotes around the filename (not just quotes around the
string, but quotes in the string itself):
#!/usr/bin/perl -w
my $file = "/My Documents/ filename";
$file =~ s/ /\\ /g;
print "$file\n";
$file = "/some other/ file name";
print qq("$file"\n);
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Sat, 29 Mar 2003 03:23:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: open fails with filename starting with space
Message-Id: <Ak8ha.3958$gp1.2361@nwrddc02.gnilink.net>
Vilmos Soti wrote:
> I was writing a program which traversed a directory structure
> (~/GNUstep), and I found that open couldn't open a filename with
> a leading space. Is there a simple way (not sysopen) around it?
Sure there is:
use File::Find;
or
use File::Recurse;
Then you don't have to write any directory traversing code at all.
jue
------------------------------
Date: Sat, 29 Mar 2003 04:24:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: open fails with filename starting with space
Message-Id: <3E85201A.84A647C5@acm.org>
Vilmos Soti wrote:
>
> I was writing a program which traversed a directory structure
> (~/GNUstep), and I found that open couldn't open a filename with
> a leading space. Is there a simple way (not sysopen) around it?
perldoc -q 'How can I open a file with a leading ">" or trailing blanks'
perldoc perlopentut
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 29 Mar 2003 00:18:38 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: open fails with filename starting with space
Message-Id: <3E852CAE.863FC6A5@earthlink.net>
Vilmos Soti wrote:
>
> Hello,
>
> I was writing a program which traversed a directory structure
> (~/GNUstep), and I found that open couldn't open a filename with
> a leading space. Is there a simple way (not sysopen) around it?
Change code like this:
open( FH, $filename )
or like this:
open( FH, "<$filename" )
into code like this:
open( FH, "<", $filename )
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 29 Mar 2003 03:54:46 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: pattern matching
Message-Id: <b635e6$3ug$1@troll.powertech.no>
>>Why don't you read the docs?
Helgi> Now, the perlop page is pretty big, 31 pages or so,
Helgi> with one hell of a lot of sections and no convenient
Helgi> way to search [...]
If you prefer reading html (with a table of contents at the top), make
a file like this
perldoc -u perlop | pod2html > perlop.html
Reading pods with lynx might be an idea:
perldoc -u perlop | pod2html | lynx -stdin
If you're lazy and like slozilla, stick this in your shells startup file
(works for sh, bash and zsh. Usage: ph perlop):
ph () { perldoc -u $1 | pod2html > /tmp/$1.html && mozilla /tmp/$1.html; }
Vim users might want to read the pod into a buffer
perldoc -u perlop | vim -
... same thing, using folding to create a nice toc
vim -c ':r!perldoc -u perlop' \
-c ':se ft=pod fdm=marker fmr==head,=cut fen sy=on'
Hope this helps,
--
Vlad
------------------------------
Date: Fri, 28 Mar 2003 19:49:46 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Perl and Objects
Message-Id: <3E84FBBA.1080509@annuna.com>
I have been reading and learning C++ and Perl. I prefer to work in Perl
is a much friendlier language. I just find creating classes and objects
in C++ much more strait forward. It might just be the difference in
refrences I have. I just find all the examples in perl very confusing
when I am still confused with objects in general. Could I get a realy
simple example of a program that creates a class may be one attribue and
one method. From that Make two objects that do something in a realy
simple program.
------------------------------
Date: 29 Mar 2003 03:50:59 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Perl and Objects
Message-Id: <b63573$9du@dispatch.concentric.net>
"Joe Creaney" <mail@annuna.com> wrote in message
news:3E84FBBA.1080509@annuna.com...
> I have been reading and learning C++ and Perl. I prefer to work in Perl
> is a much friendlier language. I just find creating classes and objects
> in C++ much more strait forward. It might just be the difference in
> refrences I have. I just find all the examples in perl very confusing
> when I am still confused with objects in general. Could I get a realy
> simple example of a program that creates a class may be one attribue and
> one method. From that Make two objects that do something in a realy
> simple program.
>
If you're confused about "objects in general," then it is likely you will be
confused about objects in particular in any particular (new) language.
Please consider studying object-oriented Perl on its own terms ... not on
those of another language.
You can start with the documentation included with Perl:
perldoc perlboot
perldoc perlobj
perldoc perltoot
Then go out get a copy of Damian Conway's Object Oriented Perl.
------------------------------
Date: Sat, 29 Mar 2003 10:19:59 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Perl modules.
Message-Id: <b62lav$13p97$1@ID-172104.news.dfncis.de>
"Phil Latio" <phil.latio@f-in-stupid.co.uk> wrote in message
news:O8Zga.6817711$6N5.919308@post-03.news.easynews.com...
>
> I should clarify that until 20 minutes, I had not heard of
> http://www.perldoc.com and it had strangely evaded me on my searches using
> Google. Therefore the phrase "perldoc -q module" didn't make any sense
> because I didn't understand in what context it had to be used. I also
don't
> currently have shell access.
So you were able to write a reasonably complex module without ever knowing
how to read the Perl documentation?
------------------------------
Date: Sat, 29 Mar 2003 01:26:52 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <wD6ha.3522461$TJ.488839@post-02.news.easynews.com>
Did you actually read the original post on this thread?
> I am reading a page from CGI Programming with Perl, Second Edition By
> Gunther Birznieks, Scott Guelich, Shishir Gundavaram.
>
> It has the code for two files:
> UserTracker.pm
> query_track.cgi
Cheers
Phil
------------------------------
Date: Fri, 28 Mar 2003 19:42:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl modules.
Message-Id: <slrnb89ugf.2ds.tadmc@magna.augustmail.com>
Phil Latio <phil.latio@f-in-stupid.co.uk> wrote:
> Did you
Who you?
Please quote someowe with an attribution of you are going to refer to someone.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 29 Mar 2003 02:20:52 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <8q7ha.3525314$TJ.489116@post-02.news.easynews.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb89ugf.2ds.tadmc@magna.augustmail.com...
> Phil Latio <phil.latio@f-in-stupid.co.uk> wrote:
>
> > Did you
>
>
> Who you?
>
> Please quote someone with an attribution of you are going to refer to
someone.
Like this? :-))
The problem I am having is working out how I am going to solve the overall
assessed piece of coursework. Been chatting to other students this evening
and none of them are using modules, just straight CGI Perl scripts (I can
cut, paste and hack to get something approaching workable).
If you are interested, this part of the ACW is to figure out how to force
someone to register on a website on the front page before entering the rest
of the website and it must be done without using passwords.
It's mostly CGI, cookies and Apache stuff but that book I mentioned threw
Perl modules into the equation.
Thanks for your help.
Cheers
Phil
------------------------------
Date: 28 Mar 2003 20:25:06 -0600
From: "Ami" <amiba128@sd6.so-net.ne.jp>
Subject: Please tell me I'm beginner
Message-Id: <3e85034e$0$55953$45beb828@newscene.com>
Hello.
I want to set a cookie in a Web page.
And I wish to make the cookie disappears, when they close the browser.
How do I change the script ?
#!/usr/bin/perl
use strict;&main;exit;
sub main{
my $id = "hello";
my $value = "";
print "Set-Cookie: ".setcookie($id,\$value);
print "Content-Type: text/plain\n\n";
print "SetCookie!!";
}
sub setcookie{
my ($id,$cookie) = @_;
my $expires = "";
my $day = 1;
$$cookie =~ s/([^\w ])/'%'.unpack('H2',$1)/eg;
$$cookie =~ tr/ /+/;
if ($day > 0){
my ($mday,$month,$year,$youbi) = (localtime(time +($day * 86400)))[3..6];
$day=('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[$d
ay];
$month=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')
[$month];
$year += 1900;
$mday = sprintf("%02d",$mday);
$expires = " expires=$youbi, $mday-$month-$year 00:00:00 GMT";
}
return "$id=$$cookie;$expires\n";
}
Please tell me.
------------------------------
Date: 29 Mar 2003 02:48:56 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Please tell me I'm beginner
Message-Id: <slrnb8a2co.ang.abigail@alexandra.abigail.nl>
Ami (amiba128@sd6.so-net.ne.jp) wrote on MMMCDXCVII September MCMXCIII in
<URL:news:3e85034e$0$55953$45beb828@newscene.com>:
:} Hello.
:} I want to set a cookie in a Web page.
:} And I wish to make the cookie disappears, when they close the browser.
:} How do I change the script ?
Do you have a Perl question?
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: 28 Mar 2003 21:25:06 -0600
From: "Ami" <amiba128@sd6.so-net.ne.jp>
Subject: Re: Please tell me I'm beginner
Message-Id: <3e851174$0$8520$45beb828@newscene.com>
Yes, off course.
Don't you think so when you read my question ?
"Abigail" <abigail@abigail.nl> wrote in message
news:slrnb8a2co.ang.abigail@alexandra.abigail.nl...
> Ami (amiba128@sd6.so-net.ne.jp) wrote on MMMCDXCVII September MCMXCIII in
> <URL:news:3e85034e$0$55953$45beb828@newscene.com>:
> :} Hello.
> :} I want to set a cookie in a Web page.
> :} And I wish to make the cookie disappears, when they close the browser.
> :} How do I change the script ?
>
>
> Do you have a Perl question?
>
>
>
> Abigail
> --
> use lib sub {($\) = split /\./ => pop; print $"};
> eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: Sat, 29 Mar 2003 03:27:13 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Please tell me I'm beginner
Message-Id: <lo8ha.3973$gp1.2331@nwrddc02.gnilink.net>
Ami wrote:
> I want to set a cookie in a Web page.
So I guess you are talking about the HTTP protocol?
> And I wish to make the cookie disappears, when they close the browser.
Well, you would set the life span of the cookie accordingly.
Of course this has nothing to do with Perl whatsoever.
You may want to ask in a NG that actually deals with things like HTTP, the
Web, and Cookies.
jue
------------------------------
Date: 28 Mar 2003 21:50:10 -0600
From: "Ami" <amiba128@sd6.so-net.ne.jp>
Subject: Re: Please tell me I'm beginner
Message-Id: <3e851766$0$34738$45beb828@newscene.com>
"J$B!&(Bgen Exner" <jurgenex@hotmail.com> wrote in message
news:lo8ha.3973$gp1.2331@nwrddc02.gnilink.net...
> Ami wrote:
> > I want to set a cookie in a Web page.
>
> So I guess you are talking about the HTTP protocol?
It thought that I was related to HTTP protocol and it massaged and it was not.
> > And I wish to make the cookie disappears, when they close the browser.
>
> Well, you would set the life span of the cookie accordingly.
> Of course this has nothing to do with Perl whatsoever.
I think relation's with Perl $B$"$k(B because I use a CGI.
> You may want to ask in a NG that actually deals with things like HTTP, the
> Web, and Cookies.
I want to know the group of the name, what, it is.
> jue
>
>
------------------------------
Date: Sat, 29 Mar 2003 04:03:01 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Please tell me I'm beginner
Message-Id: <VV8ha.429$HJ3.14@nwrddc04.gnilink.net>
Ami wrote:
> "J$B!&(Bgen Exner" <jurgenex@hotmail.com> wrote in message
> news:lo8ha.3973$gp1.2331@nwrddc02.gnilink.net...
>> You may want to ask in a NG that actually deals with things like
>> HTTP, the Web, and Cookies.
>
> I want to know the group of the name, what, it is.
You may want to see the answer to PerlFAQ9:
"My CGI script runs from the command line but not the browser. (500
Server Error)"
(just type "perldoc -q 500" and this very question with answer will pop up).
It contains pointers to NGs and several FAQs which deal with web authoring,
CGI, HTTP, ....
jue
------------------------------
Date: Fri, 28 Mar 2003 22:57:05 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: print out multi queries
Message-Id: <3E851991.471DB10A@earthlink.net>
Jeff D Gleixner wrote:
>
> Mario542 wrote:
> > Does anyone know how to get a script to print two select queries at
> > the same time? It prints the first select but not the second. Maybe
> > this cann't be done.
>
> You need 2 separate queries.
True.
> Also, no need for the prepare if
> you're not using placeholders.
False -- the 'do' method does not return SELECT results.
(Yes, one could use one of the two 'selectall_<type>ref' methods, but if
the query result is huge, they would be innefficient, both in time and
memory. Plus, these didn't exist in older versions of DBI, whereas
prepare/execute have been around forever.)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 29 Mar 2003 00:17:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: search and replace long hex string
Message-Id: <3E84E60A.35D47C81@acm.org>
Doug Kite wrote:
>
> John W. Krahn wrote:
> > It looks like you have an endian problem. Instead of specifying an
> > integer \x24F0 that may be translated to \xF024, specify the bytes
> > individually.
> >
> > perl -i -pe 's{\x24\xf0}{\x14\xf0}g' /foo/bar
> >
> > Or even better, use positive look-ahead:
> >
> > perl -i -pe 's{\x24(?=\xf0)}{\x14}g' /foo/bar
> >
> > And positive look-behind:
> >
> > perl -i -pe 's{(?<=\xb3\x01\x00\x16)\x24(?=\xf0)}{\x14}g' /foo/bar
>
> I could not get any of these to work. Only the single byte hex replace
> will work. Any other ideas?
It could be that you have an older version of Perl that doesn't
understand (?<=) and (?=).
perl -i -pe 's{(\xb3\x01\x00\x16)\x24(\xf0)}{$1\x14$2}g' /foo/bar
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 29 Mar 2003 00:29:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: search and replace long hex string
Message-Id: <3E84E8F5.B8929CD0@acm.org>
Doug Kite wrote:
>
> John W. Krahn wrote:
> >
> > perl -i -pe 's{(?<=\xb3\x01\x00\x16)\x24(?=\xf0)}{\x14}g' /foo/bar
>
> Finally got it by using tr{}{} instead of s{}{}g
>
> I don't really understand it, but it worked.
tr/// and s/// do completely different things. s/// replaces whatever
the regular expression on the left matched with the replacement string
on the right. Either can be defined at run time and can be zero or more
characters in length. tr/// replaces the character on the left with the
corresponding character on the right and must be defined at compile
time.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 28 Mar 2003 23:12:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting keys in a hash runs slower now.
Message-Id: <b62kte$51k$1@mamenchi.zrz.TU-Berlin.DE>
Nils Petter Vaskinn <no@spam.for.me.invalid> wrote in comp.lang.perl.misc:
> On Fri, 28 Mar 2003 11:29:50 +0100, Anno Siegel wrote:
>
> > Nils Petter Vaskinn <no@spam.for.me.invalid> wrote in
> > comp.lang.perl.misc:
> >
> > [...]
> >
> >> I'm quite new to perl so this is just a shot in the dark. But in most
> >> programming languages I've touched floating point arithmetic is more
> >> expensive than integer.
> >
> > That would depend both on the processor and the language, or rather the
> > specific implementation.
> >
> >> Is this the case for perl too?
> >
> > No. For one, even integers are stored and processed as floats (unless
> > you "use integer"). More importantly, the overhead in calling a Perl
> > operator is many times the cost of a numeric operation, never mind
> > which, so the difference would be insignificant in any case.
>
> Thanks for the answer.
>
> So in perl the smart thing(TM) is to use the number representation that
> seems logical, not try to force a representation to be integers.
>
> Though in this case the two representations are equally logical; Is a year
> 52 weeks or is a week 1/52 years? :)
Ah, but if you have the choice, chose an integer representation. Not
for speed, but for accuracy. Basically, integers can reasonably be
compared with "==", but floats can't. That makes a big difference.
Anno
------------------------------
Date: Fri, 28 Mar 2003 22:45:25 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting keys in a hash runs slower now.
Message-Id: <3E8516D5.9EF39986@earthlink.net>
Nils Petter Vaskinn wrote:
>
> On Fri, 28 Mar 2003 11:29:50 +0100, Anno Siegel wrote:
>
>> Nils Petter Vaskinn <no@spam.for.me.invalid> wrote in
>> comp.lang.perl.misc:
>>
>> [...]
>>
>>> I'm quite new to perl so this is just a shot in the dark. But in
>>> most programming languages I've touched floating point arithmetic is
>>> more expensive than integer.
>>
>> That would depend both on the processor and the language, or rather
>> the specific implementation.
>>
>>> Is this the case for perl too?
>>
>> No. For one, even integers are stored and processed as floats
>> (unless you "use integer"). More importantly, the overhead in
>> calling a Perl operator is many times the cost of a numeric
>> operation, never mind which, so the difference would be insignificant
>> in any case.
>
> Thanks for the answer.
>
> So in perl the smart thing(TM) is to use the number representation
> that seems logical, not try to force a representation to be integers.
>
> Though in this case the two representations are equally logical; Is a
> year 52 weeks or is a week 1/52 years? :)
If you represented a year as 52 weeks, then you would have to represent
a month as 4 1/3 weeks.
No matter what, you're going to have to resort to floating point, and
it's easiest, more logical, to convert everything to either years or
days.
Actually, days would be the best representation:
my %scale = ("Y" => 365.25, "M" => (365.25/12), "W" => 7);
....
$aval * $scale{$atype} cmp $bval * $scale{$btype};
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 28 Mar 2003 23:55:04 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Ugh. Better way to turn strings into trees. SOLUTION!
Message-Id: <3E852728.C70DBBEB@earthlink.net>
Arvin Portlock wrote:
[snip]
> foreach my $key (sort by_prefix keys %Data) {
Given the totally unordered nature of the keys() operator, ISTM that
there's no harm in keys with the same prefix, but different suffices,
compare as unequal. Thus, you could do:
foreach my $key (sort keys %Data) {
This would be a faster way to do nearly the same thing.
> my $field;
> $key =~ /:([^:]+)/ && ($field = $1);
> my $var_name;
> $key =~ /^([A-Z0-9_]+)/ && ($var_name = $1);
These probably could be combined, into:
my ($var_name, $field) =
$key =~ /^([A-Z0-9_]*)[^:]*:?([^:]*)/;
[snip]
Hmm... Here's an easier way of producing a tree data structure:
use strict;
use warnings;
my %tree;
# while/each is more memory efficient (and often
# faster, for big data) than foreach, but you can't
# use if if you need to sort.
while( my ($key, $value) = each %Data ) {
my @keys = split /(?=[-:])/, $key, -1;
my $tref = \\%tree;
$tref = \$$tref->{$_} for @keys;
$$tref = $value;
}
# Whee! That's the whole of the tree building code.
# Now, for printing out the tree:
sub printtree {
my ($prefix, $name, $leaf) = @_;
if( !ref $leaf ) {
print "$prefix$name => $leaf\n";
return;
}
$prefix = " " . $prefix if $prefix;
$prefix .= $name if $name;
printtree( $prefix, $k, $leaf->{$_} )
for sort keys %$leaf;
}
printtree( "", undef, \%tree );
__END__
[untested]
This code assumes that %Data does not have the empty string as a key.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 28 Mar 2003 22:29:43 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: why heredoc? was: Re: print here-documents question
Message-Id: <3E851327.2ED09BB1@earthlink.net>
Matija Papec wrote:
> Tad McClellan wrote:
> >> IMO, it looks terribly ugly;
> >
> >That depends on what is in the string that you are quoting.
> >
> >I think this is harder to read than the above:
> >
> > print "var newLine = unescape(\"%0A\")";
> > print "alert(\"The correct email format is : \" + newLine + \"username\@domain.extension\")";
> >
> >
> >Here docs are WYSIWYGish.
>
> Yes, but Perl quoting mechanism is even more WYSIWYG!(qq{} q{})
But the q and qq operators can only take a single character delimiter.
If you've got a really large amount of arbitrary text, it's quite likely
that any particular character you choose will occur within that text,
and will have to be escaped.
Whereas, with a here doc, you can pick a string like "asdf23409u554" or
whatever which *won't* occur within your text.
And, if you've a multi-line string, and *don't* want the first line to
be newline, then you've got to write something like:
$x = q[blah blah
blah
asdfasdf
];
Which is less pretty than the the equvilant here-doc:
$x = <<'EOS';
blah blah
blah
asdfasdf
EOS
> Here doc in great manner resembles shell scripting
Where do you think it came from? :)
> and just looks awful.
For some situations, it's awful, for others it's great.
It depends upon the situation.
And if you don't like it, you don't have to use it.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
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 4781
***************************************