[29091] in Perl-Users-Digest
Perl-Users Digest, Issue: 335 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 14 14:09:55 2007
Date: Sat, 14 Apr 2007 11:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 14 Apr 2007 Volume: 11 Number: 335
Today's topics:
Re: Creating a file to print to <hjp-usenet2@hjp.at>
Help with nested pattern. somedeveloper@gmail.com
Re: Help with nested pattern. <nobull67@gmail.com>
Re: Help with nested pattern. <nobull67@gmail.com>
Re: Help with nested pattern. somedeveloper@gmail.com
Re: Help with nested pattern. <wahab-mail@gmx.de>
Re: How to transparently download multiple files? <purlgurl@purlgurl.net>
Re: How to transparently download multiple files? <edMbj@aes-intl.com>
Re: How to transparently download multiple files? <cdalten@gmail.com>
Re: How to transparently download multiple files? <cdalten@gmail.com>
Re: How to transparently download multiple files? <purlgurl@purlgurl.net>
Re: How to transparently download multiple files? <tadmc@augustmail.com>
Re: How to transparently download multiple files? <hjp-usenet2@hjp.at>
Re: Illegal seek <rvtol+news@isolution.nl>
Re: perl regular expression <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 14 Apr 2007 14:19:17 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Creating a file to print to
Message-Id: <slrnf21hm5.a6b.hjp-usenet2@zeno.hjp.at>
On 2007-04-09 21:55, Mumia W. <paduille.4061.mumia.w+nospam@earthlink.net> wrote:
> use IO::File;
Not necessary. open works just fine since at least 5.8.
> my %groups = (
> 11 => IO::File->new(...) || die(...),
> 12 => IO::File->new(...) || die(...),
> );
>
> my $group = 1;
>
> while ($group <= 12) {
Why are you using a hash if it is indexed by small, consecutive
integers?
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: 14 Apr 2007 03:31:54 -0700
From: somedeveloper@gmail.com
Subject: Help with nested pattern.
Message-Id: <1176546714.603578.99730@l77g2000hsb.googlegroups.com>
Hi,
Would appreciate some hints on a 'smart' / 'nifty' solution to this
problem.
The problem:
I need to extract a block of text lying between -- let's say -- a
pair of brackets.
There can be an arbitrary # of such [] blocks nested one inside the
other.
I know how to mark my first '[' to start the matching process.
Example:
abc [ def .*
[ .* ]
[ .*
[ .* ]
]
uvw ] xyz
Desired output: [ def .* uvw ]
1. Now, I don't know if this is something Perl regexps can handle. I
read somewhere (possibly incorrectly) that nested patterns are in
general constructs that are handled via grammars (flex/bison combo)
and not regexps.
2. But since Perl provides features like match-time-code-evaluation in
regexps, I thought incrementing a count variable on each '[',
decrementing it on each ']', and printing the current pattern when the
count goes to zero would do the job... but I'm not so sure how.
3. If there's really no solution via regexps and grammars, I would
have to use the brute-force approach of processing each character in a
loop looking for ['s and ]'s. (yuck!)
Regards...
------------------------------
Date: 14 Apr 2007 03:42:15 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Help with nested pattern.
Message-Id: <1176547335.744577.129080@d57g2000hsg.googlegroups.com>
On 14 Apr, 11:31, somedevelo...@gmail.com wrote:
> Hi,
>
> Would appreciate some hints on a 'smart' / 'nifty' solution to this
> problem.
>
> The problem:
> I need to extract a block of text lying between -- let's say --
> a pair of brackets.
> There can be an arbitrary # of such [] blocks nested one inside
> the other.
This is FAQ: "How do I find matching/nesting anything?"
------------------------------
Date: 14 Apr 2007 04:28:55 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Help with nested pattern.
Message-Id: <1176550134.904084.40060@e65g2000hsc.googlegroups.com>
On 14 Apr, 11:42, "Brian McCauley" <nobul...@gmail.com> wrote:
> This is FAQ: "How do I find matching/nesting anything?"
Applying the suggestions given there
use strict;
use warnings;
my $in = ' abc [ def .*
[ .* ]
[ .*
[ .* ]
]
uvw ] xyz';
local our $re;
# Taken from "perldoc perlre" section dealing with (??{ })
$re = qr{
\[
(?:
(?> [^\[\]]+ )
|
(??{ $re })
)*
\]
}x;
# Find first top-level bracketed section
my ($out) = $in =~ /($re)/;
# Remove sub-brackets
$out =~ s/(?<!\A)$re//g;
# Normalize whitespace
$out =~ s/\s+/ /g;
print "$out\n";
__END__
------------------------------
Date: 14 Apr 2007 04:59:54 -0700
From: somedeveloper@gmail.com
Subject: Re: Help with nested pattern.
Message-Id: <1176551994.149831.23650@n59g2000hsh.googlegroups.com>
On Apr 14, 4:28 pm, "Brian McCauley" <nobul...@gmail.com> wrote:
> On 14 Apr, 11:42, "Brian McCauley" <nobul...@gmail.com> wrote:
>
> > This is FAQ: "How do I find matching/nesting anything?"
>
> Applying the suggestions given there
>
> use strict;
> use warnings;
>
> my $in = ' abc [ def .*
> [ .* ]
> [ .*
> [ .* ]
> ]
> uvw ] xyz';
>
> local our $re;
>
> # Taken from "perldoc perlre" section dealing with (??{ })
> $re = qr{
> \[
> (?:
> (?> [^\[\]]+ )
> |
> (??{ $re })
> )*
> \]
> }x;
>
> # Find first top-level bracketed section
> my ($out) = $in =~ /($re)/;
>
> # Remove sub-brackets
> $out =~ s/(?<!\A)$re//g;
>
> # Normalize whitespace
> $out =~ s/\s+/ /g;
>
> print "$out\n";
>
> __END__
Can't thank you enough! It was (really){2,}\.\.\. dumb on my part to
not check the faq first!
------------------------------
Date: Sat, 14 Apr 2007 14:13:50 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Help with nested pattern.
Message-Id: <evql7g$70v$1@mlucom4.urz.uni-halle.de>
somedeveloper@gmail.com wrote:
> The problem:
> I need to extract a block of text lying between -- let's say -- a
> pair of brackets.
> There can be an arbitrary # of such [] blocks nested one inside the
> other.
> I know how to mark my first '[' to start the matching process.
> Example:
> abc [ def .*
> [ .* ]
> [ .*
> [ .* ]
> ]
> uvw ] xyz
>
> Desired output: [ def .* uvw ]
If the problem stays as simple as your example,
which means: you know in advance to capture
only the outer part of something, you could
simply re-model it as a regexp and forget about
the inner structure (if you don't need it).
Example (you know you need only the "outer pair")
use strict;
use warnings;
my $text = '
abc [ def .*
[ .* ]
[ .*
[ .* ]
]
uvw ] xyz ';
my $reg;
$reg = qr/ \A # start of string
.+? (\[ \s+ \w+) \s+ (\S+) # re-model abc [ def ~~~
.* # be greedy
\b(\w+ \s+ \]) \s+ \w+ \s+ # re-model backwards
\z
/xs;
if( $text =~ /$reg/ ) {
print "$1 $2 $3"
}
If your real problem is more complicated,
then you'd go with Brians solution imho.
Regards
Mirco
------------------------------
Date: Sat, 14 Apr 2007 06:37:02 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: How to transparently download multiple files?
Message-Id: <Xb-dnTC52dyeRL3bnZ2dnUVZ_oSnnZ2d@giganews.com>
foo bar baz qux wrote:
(snipped exceptionally childish trolling)
Well gosh, aren't you the hateful little boy pissing
discontent all over the walls of this discussion group
like a stupid untrained dog.
Purl Gurl
------------------------------
Date: Sat, 14 Apr 2007 08:39:22 -0700
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: How to transparently download multiple files?
Message-Id: <6bt123pr1qbck13ipm2fnfbmmk3qglfg1t@4ax.com>
foo bar baz qux scribed:
>On Apr 7, 9:35 pm, Ed Jay <e...@aes-intl.com> wrote:
>
>Normally I don't see stuff posted by trolls. This time someone failed
>to ignore a troll and so the trolls writings became visible in Ed's
>posting. People unfamiliar with Kiralynne Schilitubi (AKA purlgurl AKA
>godzilla AKA callgirl) might like to use Google Groups to research
>PG's posting history.
>
>A small example:
>"You of the Perl Community, have successfully given the
>Perl Community a reputation of being populated by
>mentally disturbed people who are psychotically driven
>to harass all peoples, children, women, men, the elderly,
>all people, about whom you know nothing. "
>- Purl Gurl, Jun 27 2004
>
>And another:
>"you will not be made privy to illegal real world actions
>we may have or may not have taken. However, I will comment
>he suddenly fled his place of residence and never returned
>as a result of some events in his life."
>- Purl Gurl, Jun 29 2004
>
>PGs grasp on reality often seems tenuous.
>
>
>> Purl Gurl scribed:
>>> Ed Jay wrote:
>>>
>>>> I have 'n' files, sequentially numbered, on my server. I wish to
>>>> download the files without operator intervention to a local folder
>>>> of my choice.
>>>
>>> Use the LWP module for this operation.
>>> Stein's CGI.pm is not your best choice for this operation.
>
>PG has an irrational loathing of CGI.pm. Don't pay too much attention
>to PG's advice. I'm no great fan of CGI.pm but it does help those new
>to Perl and/or to HTML to produce reasonable HTML.
>
>
>>>> Issue first is that it asks me whether to open/save. I want the
>>>> script to automatically either save or open without asking.
>>>
>>> This is a result of the content type you are using in your script.
>>>
>>>> Issue second is that while the below script indeed downloads all
>>>> the files, it downloads them as a single file with the identity of
>>>> filename0. IOW, all three files are contained within filename0.
>>>
>>> This is expected. You are opening and printing three files. Upon
>>> flushing your print via CGI, all three files are printed as one. You
>>> cannot print three separate files to a single browser instance,
>>> even if a download print.
>>>
>>> You are also printing your content type, three times.
>>>
>>> A lack of "binmode" for your open and your print _might_ create
>>> issues even if you only open and print a single file.
>>>
>>>> my $imgCnt = 3;
>>>
>>> You never use this variable.
>>>
>>> What you are trying to perform is simply impossible. You cannot
>>> send three "downloads" to a browser in a single httpd transaction.
>>> What you are doing is sending three files, combined as one. Even if
>>> you download and save, this file will be corrupted and impossible to
>>> open for viewing.
>>>
>>> Research and learn about the LWP module. This LWP will perform
>>> precisely your task, with no intervention needed on your part.
>>> You only need to invoke your script through a browser, print some
>>> message to yourself, then LWP will fetch files and store files for
>>> you, in the background.
>>>
>>> You can also invoke your LWP script from a command line; no
>>> browser is needed for this task of yours. If you do not have
>>> command line access, maybe your site is hosted on a server,
>>> then use a browser
>>> to access and invoke your cgi based script.
>>>
>>> http://www.perlmonks.org/?node_id=18565
>>>
>>> http://search.cpan.org/dist/libwww-perl/bin/lwp-download
>>>
>>> http://perl.active-venture.com/lib/LWP/Simple.html
>>>
>>> The "Image-Grab" module might prove even better for your task.
>>> This module is dedicated specifically to your task,
>>>
>>> http://mah.everybody.org/hacks/perl/Image-Grab/
>>>
>
>Up to this point PGs advice isn't particularly bad and is above PG's
>norm, though PG seems to be overselling the marvels of LWP.
>
>>> Here is a simple example cgi script which will allow you to download
>>> your images and look at your images, in one shot. You only need
>>> to decide if to use LWP, LWP::Simple or Image-Grab, maybe some
>>> other technique you learn about during your research.
>>>
>>> #!perl
>>>
>>> # here you invoke a module, LWP, Image-Grab, whatever
>>> # coding examples are all over the web for you to use
>>> # you can add a "success" print to your html output
>>>
>>> print "Content-type: text/html\n\n";
>>> print "<HTML>";
>
>PG makes no attempt to write standards compliant HTML or XHTML. The
>quality of the resultant HTML is pretty poor.
>
>>>
>>> # change $imgPath to your server location:
>>>
>>> $imgPath = "http://localhost/~test/";
>>> $imgCode = 'Threeimages040407';
>
>PG makes no attempt to correct the misuse of double quotes.
>
>>>
>>> for (my $i = 0; $i < 3; $i++)
>
>PG doesn't suggest the more readable
> for my $i (0..3)
>
>>> {
>>> $imgName = $imgPath.$imgCode.$i.'.jpg';
>>> print "<img src = \"$imgName\"><BR>";
>
>Since PG has done away with the second use of $imgName it would be
>better to do away with it and combine the statements.
>
>>> }
>>>
>>># if download by a module is successful you
>>># could print a "success" message here
>>>
>>> if ($return eq "success")
>>> { print "<BR><H2> Download Successful </H2>"; }
>>> else
>>> { print "<BR><H2> FUBAR! </H2>"; }
>
>Note the useless use of double quotes.
>
>This is one place where I would introduce an extra variable in order
>to avoid repetition of HTML.
>
> print "<BR><H2>$result</H2>";
>
>But I'd write proper standards conformant XHTML - there's no reason
>not to.
>
>Using header tags for emphasis is plain wrong. Use header tags for
>things that are a heading for some following matter.
>
>>>
>>> print "</HTML>";
>
>>
>> Thank you very much.
>> --
>> Ed Jay
>
>You're too polite. PG writes code worse than I did in the Perl4 days.
For the record, I've asked for help on two or three occasions. On each
occasion I walked away offended by several responses I received (with no
help), except for hints and direction from Purl Gurl that led to both
solutions to my programming issues, and to my better understanding of Perl.
--
Ed Jay (remove 'M' to respond by email)
------------------------------
Date: 14 Apr 2007 09:31:10 -0700
From: "grocery_stocker" <cdalten@gmail.com>
Subject: Re: How to transparently download multiple files?
Message-Id: <1176568270.722572.224460@l77g2000hsb.googlegroups.com>
> >> Here is a simple example cgi script which will allow you to download
> >> your images and look at your images, in one shot. You only need
> >> to decide if to use LWP, LWP::Simple or Image-Grab, maybe some
> >> other technique you learn about during your research.
>
> >> #!perl
>
> >> # here you invoke a module, LWP, Image-Grab, whatever
> >> # coding examples are all over the web for you to use
> >> # you can add a "success" print to your html output
>
> >> print "Content-type: text/html\n\n";
> >> print "<HTML>";
>
> PG makes no attempt to write standards compliant HTML or XHTML. The
> quality of the resultant HTML is pretty poor.
>
>
Can you clarify this. I'm lost.
>
> >> # change $imgPath to your server location:
>
> >> $imgPath = "http://localhost/~test/";
> >> $imgCode = 'Threeimages040407';
>
> PG makes no attempt to correct the misuse of double quotes.
>
>
How does moronzilla abuse the doublequotes in this case?
>
------------------------------
Date: 14 Apr 2007 09:37:51 -0700
From: "grocery_stocker" <cdalten@gmail.com>
Subject: Re: How to transparently download multiple files?
Message-Id: <1176568671.268553.144090@w1g2000hsg.googlegroups.com>
> >> #!perl
>
> >> # here you invoke a module, LWP, Image-Grab, whatever
> >> # coding examples are all over the web for you to use
> >> # you can add a "success" print to your html output
>
> >> print "Content-type: text/html\n\n";
> >> print "<HTML>";
>
> PG makes no attempt to write standards compliant HTML or XHTML. The
> quality of the resultant HTML is pretty poor.
>
>
Can you clarify this? I'm lost.
>
> >> # change $imgPath to your server location:
>
> >> $imgPath = "http://localhost/~test/";
> >> $imgCode = 'Threeimages040407';
>
> PG makes no attempt to correct the misuse of double quotes.
>
>
How does moronzilla misuse the double quotes in this case?
Chad
------------------------------
Date: Sat, 14 Apr 2007 09:49:46 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: How to transparently download multiple files?
Message-Id: <MrOdnVXjJ4Ozm7zbnZ2dnUVZ_gidnZ2d@giganews.com>
Ed Jay wrote:
> foo bar baz qux wrote:
>> Ed Jay wrote:
(snipped a lot - read thread for context)
> For the record, I've asked for help on two or three occasions. On each
> occasion I walked away offended by several responses I received (with no
> help), except for hints and direction from Purl Gurl that led to both
> solutions to my programming issues, and to my better understanding of Perl.
The boy is trolling. This "foo bar baz qux" nym shifts then
appears for no reason other than to troll. I am his only
target of abuse. The boy has some personality disorders.
Your "...led to both solutions...better understanding...." is
an important statement.
After decades of classroom teaching, I know the best way to
prompt a person to learn is to "nudge" this person in the
right direction for individual research and learning.
Providing answers to the most basic notions of a question
is important. Additionally, leaving out details of no real
importance is equally important. This "nudging" is to
provide resolution for the most obvious, to provide a
simple foundation of understanding, then nudge a person
to continue on with seeking more detailed answers.
Spoon feeding a person causes more harm than good.
In your case example, we discussed the most basic nature
of your problem, this httpd transaction business. You
learned just enough to realize the nature of the problem.
After this, you are provided key terms and key programs
which might lead to solving your problem.
When I respond to articles like yours, I treat a person
as a reasonably intelligent person who can resolve his
problems with some hints, some nudging. Most people are
insulted when treated like an ignorant baby who needs to
be taken by the hand then walked to a goal.
We discussed some simple notions, you took those notions
and used those notions as a basis for your research and
learning. On your own, you found your answers, resolved
your problem and learned a lot in the process. On your
own, you taught yourself more than any given person could
teach you through a discussion group article.
You are a mature intelligent person. For me to treat
you as something less would truly be insulting. You
only needed a little guidance, as we all do with these
technical issues. All I really did is to pat you on
your back then point a finger in the right direction.
I consider this to be appropriate respectful behavior.
Purl Gurl
------------------------------
Date: Sat, 14 Apr 2007 13:21:31 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to transparently download multiple files?
Message-Id: <slrnf226tb.suh.tadmc@tadmc30.august.net>
grocery_stocker <cdalten@gmail.com> wrote:
[ attribution missing... ]
>> >> $imgPath = "http://localhost/~test/";
>> PG makes no attempt to correct the misuse of double quotes.
>>
>>
> How does moronzilla misuse the double quotes in this case?
I expect it is because she does not make use of either of the two
extra things that double quotes gives you over single quotes. Namely
variable interpolation and backslash escapes.
It is merely a style issue, and calling it a misuse is perhaps going
too far, though I would have suggested changing it in a code review.
Using double quotes when they are not needed is misleading, which
is bad for maintenance.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 14 Apr 2007 19:46:48 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to transparently download multiple files?
Message-Id: <slrnf224s8.b72.hjp-usenet2@zeno.hjp.at>
On 2007-04-07 18:15, Jürgen Exner <jurgenex@hotmail.com> wrote:
> You may want to check the HTTP protocol to find out if and how to
> include multiple files in a single HTTP response. If that is not
> possible, then maybe use a protocol that was designed to transfer
> files rather than hypertext.
Like SMTP? Off the top of the head I can't think of any other protocol
where multiple files are commonly transferred in a single message (I'm
missing something obvious, of course). File transfer protocols (like FTP
or HTTP) are typically designed so that the client requests one file (or
even part of a file) at a time. It can request lots of files of course,
but the client has to do this explicitely - the server doesn't reply to
a single request with multiple files. Incidentally, with HTTP this would
work in theory (the browser could respond with a response of type
multipart/mixed) but AFAIK nobody ever specified what the client should
do and I doubt that browsers do something useful. In practice the best
way to do send "multiple files" is probably to pack them into a zip file
and let the user extract them.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Sat, 14 Apr 2007 13:10:48 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Illegal seek
Message-Id: <evqk2b.1f8.1@news.isolution.nl>
Eric schreef:
> For
> clarity reasons, I didn't include all of the code.
:(
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 14 Apr 2007 13:40:53 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: perl regular expression
Message-Id: <evqlqr.1ak.1@news.isolution.nl>
kiranmn@my-deja.com schreef:
> Following RE works for me, but it fails for two consecutive
> doublequotes.
> Why RE is failing to replace second double quote, even with /g ?
>
> $input='abc "" c " de';
> print "input is $input\n";;
> $input=~ s/([^\\x])"/$1\\"/g;
> print "output is $input\n";;
You could use
1 while $input =~ s/([^\\x])"/$1\\"/;
but that would go wrong for a " at the start anyway.
This way is much clearer:
#!/usr/bin/perl
use strict;
use warnings;
my $input = q{"abc "\\" c " de};
print qq{input is $input\n};
for (1..4) {
$input =~ s# (?<! \\ ) " #\\"#xg;
print qq{output is $input\n};
}
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 335
**************************************