[17780] in Perl-Users-Digest
Perl-Users Digest, Issue: 5200 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 26 09:05:40 2000
Date: Tue, 26 Dec 2000 06:05:09 -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: <977839509-v9-i5200@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 26 Dec 2000 Volume: 9 Number: 5200
Today's topics:
Re: A better explanation of what I'm attempting <a.v.a@home.nl>
Re: A better explanation of what I'm attempting <sdfg@asd.g>
Any good Perl books? <javakit@singnet.com.sg>
Re: Any good Perl books? <perl@dotexpress.com>
Re: Any good Perl books? (Abigail)
Re: Choose which DBM by trial and error? (Abigail)
converting code to mod perl (should I use globals?) <news@#nospam#althepal.com>
Re: Error from MIME::Lite (Abigail)
Re: file size - outside url? (Joe Smith)
Re: heredoc within heredoc (Abigail)
Re: heredoc within heredoc <bart.lateur@skynet.be>
Re: heredoc within heredoc (Martien Verbruggen)
Re: heredoc within heredoc (Martien Verbruggen)
Re: If I don't want to 'goto' <johnlin@chttl.com.tw>
Re: making unique list of words matching a pattern <iltzu@sci.invalid>
Re: making unique list of words matching a pattern (Abigail)
Re: regexp question <Jerome.Abela@free.fr>
Re: regexp question <bart.lateur@skynet.be>
regexp with NULLs <flec@flec.co.uk>
Re: Syntax for "eq" and "||" (Mark-Jason Dominus)
Text Conversion in Perl <mario@alamar.net>
Re: Text Conversion in Perl (Abigail)
Re: Text Conversion in Perl <mario@alamar.net>
Re: what the hell is wrong with this ?????? <a.v.a@home.nl>
Re: what the hell is wrong with this ?????? (Martien Verbruggen)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 26 Dec 2000 12:57:54 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: A better explanation of what I'm attempting
Message-Id: <3A48972F.802513AD@home.nl>
Studio 51 wrote:
> Ok, I have a database of directory names. Every entry has 2 important
> columns:
>
is that a file acting as a database or oracle or mysql or some other?
------------------------------
Date: Tue, 26 Dec 2000 13:53:00 GMT
From: "S51" <sdfg@asd.g>
Subject: Re: A better explanation of what I'm attempting
Message-Id: <0p126.154466$_5.34505508@news4.rdc1.on.home.com>
"AvA" <a.v.a@home.nl> wrote in message news:3A48972F.802513AD@home.nl...
> is that a file acting as a database or oracle or mysql or some other?
mysql
LKembel
------------------------------
Date: Tue, 26 Dec 2000 19:46:45 +0800
From: "Peter Lai" <javakit@singnet.com.sg>
Subject: Any good Perl books?
Message-Id: <92a09u$1v$1@mango.singnet.com.sg>
Any recommendations for good reference
books on Perl?
Thanks
------------------------------
Date: Tue, 26 Dec 2000 20:00:06 +0800
From: "TommyAu@497179" <perl@dotexpress.com>
Subject: Re: Any good Perl books?
Message-Id: <92a159$8of$1@taliesin.netcom.net.uk>
go to see see :
http://perl.oreilly.com
Peter Lai <javakit@singnet.com.sg> wrote in message
news:92a09u$1v$1@mango.singnet.com.sg...
> Any recommendations for good reference
> books on Perl?
>
> Thanks
>
>
>
>
>
------------------------------
Date: 26 Dec 2000 12:11:49 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Any good Perl books?
Message-Id: <slrn94h2o5.3un.abigail@tsathoggua.rlyeh.net>
TommyAu@497179 (perl@dotexpress.com) wrote on MMDCLXXIV September
MCMXCIII in <URL:news:92a159$8of$1@taliesin.netcom.net.uk>:
[] go to see see :
[] http://perl.oreilly.com
Which will show a lot of bad and average books, and misses out most
of the better books on Perl.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: 26 Dec 2000 10:50:57 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Choose which DBM by trial and error?
Message-Id: <slrn94gu0h.3un.abigail@tsathoggua.rlyeh.net>
Ronald Schmidt (RonaldWS@software-path.com) wrote on MMDCLXXIV September
MCMXCIII in <URL:news:3A480758.A8DF8355@software-path.com>:
`` I am working on a programming that will try to deal with DBMs
`` generically. I want a user to be able to address a DBM file, preferably
`` without the need for the user to specify which kind of DBM file it is
`` (DB_File or NDBM_File etc.) Is it safe to approach this by trying to
`` tie the file O_RDONLY with several different DBM packages and see which
`` one gives a good return value from tie? If tie gives a good return code
`` O_RDONLY will it then be safe to tie the file name for read/write and do
`` updates? I have appended some sample code to illustrate the question.
You want to use AnyDBM_File.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Tue, 26 Dec 2000 09:30:31 GMT
From: Alex Hart <news@#nospam#althepal.com>
Subject: converting code to mod perl (should I use globals?)
Message-Id: <XyZ16.5128$He.1872275@typhoon2.ba-dsg.net>
I just want to say that after coding Perl for over a year now, I just
learned the difference between a global and a lexical variable. At least
I think I understand.
I have some code that I want to convert to mod perl, but I would also
like it to work outside of mod perl.
I use a whole bunch of lexical variables in the code that are used in
several subroutines. This works fine outside of mod perl, but since mod
perl puts my code inside another subroutine, I get closure in places
that I don't want it.
To fix this I figure I need to either use global variable, or pass all
the variables to all of the functions. Passing all the variables seems
like a lot of work, and too easy to make a mistake with. There are about
30 variables that are shared by the subroutines.
Can someone tell me if I am making a mistake using so many globals? I
realize that lexical variables are a little faster, but I don't expect
to overlap namespace with anyone. Are there other considerations I
should think about??
I can't believe there's not a switch so that nested subroutines can
share lexical variables. That would make life so much easier for people
switching to mod perl. Is this a silly idea?
--
- Alex Hart
$j="592888088758319859281631592858792919873179698955";
$p="push\@_,";$c="chop(\$_)";$_="$p$p($c.$c)+19;eval;
+".$j;eval;%_=map{chr}reverse@_;foreach(sort+keys%_){print$_{$_}}
------------------------------
Date: 26 Dec 2000 11:00:48 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Error from MIME::Lite
Message-Id: <slrn94guj0.3un.abigail@tsathoggua.rlyeh.net>
Randy Harris (harrisr@bignet.net) wrote on MMDCLXXIV September MCMXCIII
in <URL:news:t4gcgvl9orb148@corp.supernews.com>:
`' The code and sub below are from MIME::Lite 2.104, file Lite.pm. When it
`' is run with the -w switch it generates the following warning:
`'
`' Unrecognized escape \s passed through at (eval 2) line 11
`'
`' Simply having "use MIME::Lite ;" in the program causes it to report the
`' warning. The warning is coming from this line:
`'
`' my $SEP = "(?:^\\s*|\\s*,\\s*)"; ### before elems in a list
`'
`' I was able to confirm that this was the line by putting a line above it,
`' which changed the reported warning line number, then a line after it,
`' which did not. Aside from the warnings, the module seems to work fine.
`' $SEP appears to be used only in this one sub.
`'
`' perlop describes ?: as the ternary operator but doesn't clearly explain
`' what that line does.
Well, the fact that ?: is the ternary operator is totally irrelevant.
The above line simply assigns a string to a scalar.
`' How can I correct this, or, should I simply ignore the warnings?
Change the double quotes to single quotes.
`' sub extract_addrs {
`' my $str = shift;
`' my @addrs;
`' $str =~ s/\s/ /g; ### collapse whitespace
Eh, no, it doesn't. It just changes all whitespace to spaces.
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: 26 Dec 2000 11:21:17 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: file size - outside url?
Message-Id: <929uvd$vvq$1@nntp1.ba.best.com>
In article <3A441686.D6FCA7@wsb.com>, Jeff Helman <jhelman@wsb.com> wrote:
>Tad McClellan wrote:
>
>> You don't need to fetch the whole URL to determine the size,
>> just the headers will do.
>
>Uh, I disagree. This only works if the URL requests a static file
>(which the example does, I admit.) If, though, the URL was
>http://www.somesite.com/text.pl, and if the script did not return a
>Content-length header, then the headers are useless (at least for our
>purposes here). And I have seen sites out there that use the .txt
>extension to map to a CGI, so the safest way to get the length value of
>a URL is to retrieve the whole thing and then call length().
That's very inefficent.
Use the HEAD method first, and get the Content-Length from that.
Use GET only if the first method fails.
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: 26 Dec 2000 11:13:51 GMT
From: abigail@foad.org (Abigail)
Subject: Re: heredoc within heredoc
Message-Id: <slrn94gvbf.3un.abigail@tsathoggua.rlyeh.net>
Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMDCLXXIV September
MCMXCIII in <URL:news:slrn94g8b9.8i7.mgjv@martien.heliotrope.home>:
:: On Tue, 26 Dec 2000 11:16:51 +0800,
:: John Lin <johnlin@chttl.com.tw> wrote:
:: > "Martien Verbruggen" wrote
:: >
:: >> Do you have an actual need for this,
:: >
:: > Well the actual case is that my code
:: >
:: > parse(<<HTML,<<RULE,<<EMAIL);
:: >
:: > works, but
:: >
:: > parse(
:: > <<HTML, # my boss asked me to separate
:: > <<RULE, # them into 3 lines and add
:: > <<EMAIL # comments to explain them
:: > );
::
:: That is interesting. I didn't know about this particular oddness.
::
:: It is explainable though, although not entirely [1]. The documentation
:: states that:
::
:: A line-oriented form of quoting is based on the shell
:: "here-document" syntax. Following a `<<' you specify a
:: string to terminate the quoted material, and all lines
:: following the current line down to the terminating string
:: are the value of the item.
::
:: If the start of the various here-docs is on the same line, they should
:: all start on the line after that. If you split it out over multiple
:: lines, that breaks.
::
:: The fact that you can stack multiple ones on one line is also
:: documented, albeit only by example. From perldata:
::
:: print <<"foo", <<"bar"; # you can stack them
:: I said foo.
:: foo
:: I said bar.
:: bar
::
:: myfunc(<<"THIS", 23, <<'THAT');
:: Here's a line
:: or two.
:: THIS
:: and here's another.
:: THAT
::
:: Impied is that there is a special case made for stacked here-docs on one
:: line. There is no special case for stacked here-docs in a single
:: statement, split over several lines. This is just one of these places
:: where perl's DWIMmery does something partways. I doubt it would be easy
:: to allow the special case for multiple here-docs within the same
:: statement to work as it does within the same line.
But it does! All you need is the correct syntax.
print <<"foo",
I said foo.
foo
<<"bar";
I said bar.
bar
:: It is not implausible to call this a bug. The fact that multiple
:: here-docs on one line works is one of those special cases that Perl has
:: so many of. That this special case has limitations is not that great.
What you are asking is to special case a here doc where the first line
starts with whitespace, followed by <<.
But what should this do:
print <<foo
,<<bar;
I said foo
foo
;
Should it print " ,<<bar;\nI said foo\n", Or should it start with
"I said foo\n;\n" and continue till it finds a line with "bar" on it?
:: You could consider writing up a bug report, and ask them to at least fix
:: the documentation, or extend the ehaviour of here-docs to allow multiple
:: here-docs in the same statement (this last one is probably not trivial
:: to implement).
I would even be non-trivial to describe the syntax, let alone implement.
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Tue, 26 Dec 2000 11:51:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: heredoc within heredoc
Message-Id: <n71h4tcrrao0gt81d484v5ru78mnrtmr09@4ax.com>
Martien Verbruggen wrote:
>That is interesting. I didn't know about this particular oddness.
You didn't? I sometimes use it to append alternative strings:
print $condition?<<"TRUE":<<"FALSE";
This string is printed when condition is true.
TRUE
This string is printed when condition is false.
FALSE
but not too often.
>There is no special case for stacked here-docs in a single
>statement, split over several lines.
Oh yes there is.
parse(
<<HTML, # my boss asked me to separate
This is part of HTML
HTML
<<RULE, # them into 3 lines and add
This is part of RULE
RULE
<<EMAIL # comments to explain them
This is part of EMAIL
EMAIL
);
There's no way Perl could determine that the next line is part of the
current statement, and no a literal string. So it doesn't try. It could
even be valid perl code! It's still just text to Perl. For example:
parse(
<<HTML, # my boss asked me to separate
<<RULE, # them into 3 lines and add
<<EMAIL # comments to explain them
This is the last line of the text -- but not the first!
HTML
);
That passes one argument to the function: from the line starting with
"<<RULE," up to the line that is obviously text.
--
Bart.
------------------------------
Date: Wed, 27 Dec 2000 00:23:07 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: heredoc within heredoc
Message-Id: <slrn94h6tr.8i7.mgjv@martien.heliotrope.home>
On 26 Dec 2000 11:13:51 GMT,
Abigail <abigail@foad.org> wrote:
> Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMDCLXXIV September
> MCMXCIII in <URL:news:slrn94g8b9.8i7.mgjv@martien.heliotrope.home>:
>::
>:: It is explainable though, although not entirely [1]. The documentation
>:: states that:
>::
>:: A line-oriented form of quoting is based on the shell
>:: "here-document" syntax. Following a `<<' you specify a
>:: string to terminate the quoted material, and all lines
^^^^^^^^^
>:: following the current line down to the terminating string
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>:: are the value of the item.
>::
>:: If the start of the various here-docs is on the same line, they should
>:: all start on the line after that. If you split it out over multiple
>:: lines, that breaks.
>::
>:: The fact that you can stack multiple ones on one line is also
>:: documented, albeit only by example. From perldata:
>::
>:: print <<"foo", <<"bar"; # you can stack them
>:: I said foo.
>:: foo
>:: I said bar.
>:: bar
>::
>:: myfunc(<<"THIS", 23, <<'THAT');
>:: Here's a line
>:: or two.
>:: THIS
>:: and here's another.
>:: THAT
>::
>:: Impied is that there is a special case made for stacked here-docs on one
>:: line. There is no special case for stacked here-docs in a single
>:: statement, split over several lines. This is just one of these places
>:: where perl's DWIMmery does something partways. I doubt it would be easy
>:: to allow the special case for multiple here-docs within the same
>:: statement to work as it does within the same line.
>
> But it does! All you need is the correct syntax.
>
> print <<"foo",
> I said foo.
> foo
> <<"bar";
> I said bar.
> bar
Read upthread (<slrn948ner.8i7.mgjv@martien.heliotrope.home>) for an
article where I actually describe that. It is however not the same thing
as described in perldata.
print <<"foo", <<"bar";
I said foo
foo
I said bar
bar
And this particular case is not covered by the documentation, but by
example alone. What you describe, and what I described in an earlier
article in this thread is covered by the documentation, and isn't one of
those special cases.
I have highlighted the quote from perldata above to show why the
abovementioned example isn't covered by the documentation text. If it
was, then the "bar" here-doc would contain everything contained by the
"foo" here-doc, plus the foo end-of-string label, plus the next line. It
doesn't. It starts just after the foo label. This is special behaviour.
This special behaviour doesn't extend itself to multiple here-docs
spread out over more than one line, but is limited to mltiple here-docs
on the same line.
Yes, there are other ways of achieving multiple here-docs on multiple
lines. That much had already been established up-thread. The question
was this particular special case.
>:: It is not implausible to call this a bug. The fact that multiple
>:: here-docs on one line works is one of those special cases that Perl has
>:: so many of. That this special case has limitations is not that great.
>
> What you are asking is to special case a here doc where the first line
> starts with whitespace, followed by <<.
>
> But what should this do:
>
> print <<foo
> ,<<bar;
> I said foo
> foo
> ;
>
>
> Should it print " ,<<bar;\nI said foo\n", Or should it start with
> "I said foo\n;\n" and continue till it finds a line with "bar" on it?
And that is why I said that it could be hard to implement this. And
maybe that is why it isn't implemented that way, and limited to
here-docs that start on the same line. When they don't too many
ambiguities would be possible, and more DWIMmery would be necessary,
with more odd-ball special cases.
>:: You could consider writing up a bug report, and ask them to at least fix
>:: the documentation, or extend the ehaviour of here-docs to allow multiple
>:: here-docs in the same statement (this last one is probably not trivial
>:: to implement).
>
> I would even be non-trivial to describe the syntax, let alone implement.
agreed. But then, the syntax for the particular cas eof multiple
here-docs on one line isn't described either (only examples are given),
so the bug report could be limited to extending the textual
documentation of here-documents.
Martien
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: Wed, 27 Dec 2000 00:31:53 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: heredoc within heredoc
Message-Id: <slrn94h7e9.8i7.mgjv@martien.heliotrope.home>
On Tue, 26 Dec 2000 11:51:49 GMT,
Bart Lateur <bart.lateur@skynet.be> wrote:
> Martien Verbruggen wrote:
>
>>That is interesting. I didn't know about this particular oddness.
>
> You didn't? I sometimes use it to append alternative strings:
Nope. Never used it, or even felt the need to :)
>>There is no special case for stacked here-docs in a single
>>statement, split over several lines.
>
> Oh yes there is.
>
> parse(
> <<HTML, # my boss asked me to separate
> This is part of HTML
> HTML
> <<RULE, # them into 3 lines and add
> This is part of RULE
> RULE
> <<EMAIL # comments to explain them
> This is part of EMAIL
> EMAIL
> );
See my reply to Abigail's post. I know about this, and have even given
this same syntax upthread, but that isn't what I meant by the statement
above. I obviously wasn't being very clear. What I meant is that in this
particular case:
myfunc(<<"THIS", 23, <<'THAT');
Here's a line
or two.
THIS
and here's another.
THAT
perl knows that the second here-doc starts after the THIS label, and not
at the line immediately following the start of the here-doc. When that
first statement gets split over multiple lines, as the OP was attempting
to do, that magical knowledge disappears, because the parser sees the
second line of the statement as part of the here-doc:
myfunc(<<"THIS",
23, # THIS here-doc will start here
<<'THAT');
Here's a line
or two.
THIS
and here's another.
THAT
And this will result in syntax errors. It is understandable that this is
so, given the complexity (or even impossibility) of making this work as
expected, but it does draw the attention to the fact that the syntax
that does work is a bit special.
> There's no way Perl could determine that the next line is part of the
> current statement, and no a literal string. So it doesn't try. It could
> even be valid perl code! It's still just text to Perl. For example:
I'm not entirely convinced that it wouldn't be _possible_ to do it, but
I do agree that it would be hard, tedious, and difficult to do
correctly. It would probably end up being a minefield of ambiguity and
special cases that would make it harder to deal with than it is now.
That's why I suggested first to adapt the documentation to at least
explain (in text) what multiple here-doc starts on a single line do, and
that they are, in fact, different from a single one.
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Tue, 26 Dec 2000 11:38:04 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: If I don't want to 'goto'
Message-Id: <9293v4$elk@netnews.hinet.net>
<miko@idocs.com> wrote
> "John Lin" wrote:
> > Recently I tried to modify the structure of a program
> > to avoid using 'goto'.
> last and next are often handy in situations like you describe. For
> example, your code could be reworked like this:
>
> DIRLOOP:
> for my $file (<*>) {
>
> TESTBLOCK:
> {
> if($fail_condition1) { warn "message 1"; last TESTBLOCK;}
> if($fail_condition2) { warn "message 2"; last TESTBLOCK;}
> if($fail_condition3) { warn "message 3"; last TESTBLOCK;}
>
> next DIRLOOP;
> }
>
> rename $file => "fail/$file"; # move to fail/ sub directory
> }
>
Great!!! Following your hint, I found continue{} can also apply
to a non-loop BLOCK.
{ print "hello"; next } continue { print ", world" } # hello, world
{ print "hello"; last } continue { print ", world" } # hello
But this discovery seems to be of little help. :)
Thank you.
John Lin
------------------------------
Date: 26 Dec 2000 10:13:36 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: making unique list of words matching a pattern
Message-Id: <977824878.8293@itz.pp.sci.fi>
In article <slrn94ga7k.b6h.tadmc@magna.metronet.com>, Tad McClellan wrote:
>
>Right. My goal is to convert the one-liner to a full-up program.
>I'll try it here, on the fly, UNTESTED:
>
>use warnings; # -w
>while (<>) { # -n
> chomp; # -l
>
> @F = split; # -a and split()'s double default
>
> foreach (@F) { # map() is a foreach() in disguise
> if ( /\.cpp$/ ) {
> print "$_\n"; # -l again
> }
> }
>}
Looks about right. Here's what B::Deparse says:
$ perl -MO=Deparse -alne'map/\.cpp$/&&print,@F'
-e syntax OK
LINE: while (defined($_ = <ARGV>)) {
chomp $_;
@F = split(/\s+/, $_, 0);
map((/\.cpp$/ && print($_)), @F);
}
That can be simplified by removing optional parts:
while (<>) {
chomp;
@F = split /\s+/;
map /\.cpp$/ && print, @F;
}
But that's not quite right, is it? Your version, without the /\s+/,
produces the correct behavior of ignoring leading spaces. It seems
I've ended up tickling yet another B::Deparse bug.
--
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: 26 Dec 2000 10:35:02 GMT
From: abigail@foad.org (Abigail)
Subject: Re: making unique list of words matching a pattern
Message-Id: <slrn94gt2m.3un.abigail@tsathoggua.rlyeh.net>
Ilmari Karonen (iltzu@sci.invalid) wrote on MMDCLXXIV September MCMXCIII
in <URL:news:977824878.8293@itz.pp.sci.fi>:
`` In article <slrn94ga7k.b6h.tadmc@magna.metronet.com>, Tad McClellan wrote:
`` >
`` >Right. My goal is to convert the one-liner to a full-up program.
`` >I'll try it here, on the fly, UNTESTED:
`` >
`` >use warnings; # -w
`` >while (<>) { # -n
`` > chomp; # -l
`` >
`` > @F = split; # -a and split()'s double default
`` >
`` > foreach (@F) { # map() is a foreach() in disguise
`` > if ( /\.cpp$/ ) {
`` > print "$_\n"; # -l again
`` > }
`` > }
`` >}
``
`` Looks about right. Here's what B::Deparse says:
``
`` $ perl -MO=Deparse -alne'map/\.cpp$/&&print,@F'
`` -e syntax OK
``
`` LINE: while (defined($_ = <ARGV>)) {
`` chomp $_;
`` @F = split(/\s+/, $_, 0);
`` map((/\.cpp$/ && print($_)), @F);
`` }
``
`` That can be simplified by removing optional parts:
``
`` while (<>) {
`` chomp;
`` @F = split /\s+/;
`` map /\.cpp$/ && print, @F;
`` }
``
`` But that's not quite right, is it? Your version, without the /\s+/,
`` produces the correct behavior of ignoring leading spaces. It seems
`` I've ended up tickling yet another B::Deparse bug.
Furthermore, B::Deparse only signals one of the features of -l, the chomp.
The implicite newline after printing isn't shown.
Not even Perl can parse Perl, only perl can. ;-)
Abigail
--
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print
qq{Just Another Perl Hacker\n}}}}}}}}}' |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w
------------------------------
Date: Tue, 26 Dec 2000 08:36:44 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: regexp question
Message-Id: <3A4857C7.DDF0B103@free.fr>
Hi, Robert.
Sportbike World a écrit :
> This is Robert Basil (Sorry for the different posting address, but I am
> at work)
>
> Your idea below does not remove anything from the text file.
>
> > Let's restate the problem this way (tell me if i'm wrong): you want to
> > remove 2 blocks delimited with 53-period lines. Here is regexp which
> > does it:
> >
> > s/\.{53}.*?\.{53}//sg;
Well... It works for me. Maybe there is something different in your real
data ?
Here is a script which works for me:
--------------------------------------
#!/usr/bin/perl -w
$_ = '.'x53
. "\nText to remove\n"
. '.'x53
. "\nText to keep\n"
. '.'x53
. "\nText to remove\n"
. '.'x53
. "\n";
print "Before:\n$_";
s/\.{53}.*?\.{53}//sg;
print "After:\n$_";
--------------------------------------
Jerome.
------------------------------
Date: Tue, 26 Dec 2000 11:57:25 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regexp question
Message-Id: <gq1h4toav2rgal87nh8j1ru2iilcn0fu76@4ax.com>
Sportbike World wrote:
>but I need to
>remove:
>
>###Begin Example Message###
>
>.....................................................
>remove this text
>.....................................................
>
>keep this text
>
>.....................................................
>remove this text
>.....................................................
>
>###End Example Message###
Go for split(). In particular, pull this "message" into one string, do
@parts = split /^\.{40,}$/
and you'll get an array of message parts. You can pick out the parts you
want to keep, and join them back together with whatever you want, even
those silly lines of dots.
--
Bart.
------------------------------
Date: Tue, 26 Dec 2000 14:02:50 +0000
From: Steven Fletcher <flec@flec.co.uk>
Subject: regexp with NULLs
Message-Id: <92a8c1$ldq$1@soap.pipex.net>
Hi all.
Someone is bound to be able to help me here, because I just know that
I'm doing something totally wrong ;-)
Basically I have a perl program thats converting data from a simple
flat-file database into SQL strings to be executed via DBI. However for
one of the values that I need to fetch, the data was probably handled by
the original C in a null-terminated fashion - i.e., there were 32 bytes,
the first X (up untill a 0x00) were useful, and the rest were discarded.
However the function that reads the data simply takes 32 bytes from the
filehandle and returns it. I attempted to write a function that would
strip anything following a \00 from the data supplied, which went
something like this:
sub read_memo_sender {
($string) = @_;
if ($string =~ /^(\w+)\00/) {
return($1);
} else {
return($string);
}
}
Which worked, so long as the initial data didn't contain a Ł, or some
other non-word char. I tried replacing this with a \S, but had even less
luck. I don't know if a null byte will match a \S, though. In the end, I
reverted to something disgusting:
sub read_memo_sender {
($string) = @_;
@chars = split(//, $string);
$newstring = "";
foreach $char (@chars) {
if ($char eq "\00") {
return($newstring);
} else {
$newstring .= $char;
}
}
return($newstring);
}
.. which although I dreaded it, didn't appear to slow things down that
much. Nevertheless, I would still like to try and get the one-line
regexp working, so it'll destroy anything after a null and return
anything before it. Question is, can anyone tell me where I went wrong?
Thanks a lot;
Steven Fletcher
flec@flec.co.uk
------------------------------
Date: Tue, 26 Dec 2000 10:11:11 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Syntax for "eq" and "||"
Message-Id: <3a486ebf.56fd$233@news.op.net>
In article <G65M60.E3L@presby.edu>, Jon Bell <jtbell@presby.edu> wrote:
>As in most programming languages the comparision operators like 'eq' are
>all "binary" operators that require two operands. Evaluating them gives
>Boolean (logical) results that you can in turn combine with the Boolean
>operators such as '&&' and '||'.
If Damian's Quantum Superpositions thing goes into Perl 6, you'll be
able to write
if ($in{'Contact_Country'} eq any("Australia","Canada","UK"))
{
...
}
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Tue, 26 Dec 2000 09:03:30 -0000
From: "Mario Thomas" <mario@alamar.net>
Subject: Text Conversion in Perl
Message-Id: <J6Z16.2530$I5.28530@stones>
Hi All,
I'm receiving a text file from another department in my company which
contains an article which has previously been published in a newspaper. The
purpose of the file is to upload it to the net - thereby replicating our
newspaper content online. The problem i have is that the file contains all
sorts of strange characters. I can only
assume they have been put there by Quark on the Mac. Is there anyway i can
convert these characters to PC format using Perl? I have pasted in a sample
below:
<START TEXT>
The Phillips Report into the BSE crisis found there had been Ňa clear policy
restricting the disclosure of information about BSEÓ that robbed those with
an interest of any power to react. MP Tony Benn reckons backbench MPs need a
Freedom of Information Act as much as anybody, such is the ethos of secrecy
around the higher Zchelons of government. But, say disappointed campaigners,
this Bill is fairly toothless.
<ENDTEXT>
Any help or suggestions would be very much appreciated.
Thanks in advance
Mario
------------------------------
Date: 26 Dec 2000 11:16:48 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Text Conversion in Perl
Message-Id: <slrn94gvh0.3un.abigail@tsathoggua.rlyeh.net>
Mario Thomas (mario@alamar.net) wrote on MMDCLXXIV September MCMXCIII in
<URL:news:J6Z16.2530$I5.28530@stones>:
==
== The problem i have is that the file contains all
== sorts of strange characters. I can only
== assume they have been put there by Quark on the Mac. Is there anyway i can
== convert these characters to PC format using Perl?
tr/// will do. You have to make your own mapping of course.
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: Tue, 26 Dec 2000 11:27:42 -0000
From: "Mario Thomas" <mario@alamar.net>
Subject: Re: Text Conversion in Perl
Message-Id: <Xd%16.2760$I5.29687@stones>
I thought about using tr/// the problem with that is that i will have to
create the mappings as they happen. I would prefer to find out what
character sets i am translating between. Is there a way to do this or is
there a list of character sets somewhere?
"Mario Thomas" <mario@alamar.net> wrote in message
news:J6Z16.2530$I5.28530@stones...
> Hi All,
>
> I'm receiving a text file from another department in my company which
> contains an article which has previously been published in a newspaper.
The
> purpose of the file is to upload it to the net - thereby replicating our
> newspaper content online. The problem i have is that the file contains all
> sorts of strange characters. I can only
> assume they have been put there by Quark on the Mac. Is there anyway i can
> convert these characters to PC format using Perl? I have pasted in a
sample
> below:
> <START TEXT>
>
> The Phillips Report into the BSE crisis found there had been Ňa clear
policy
> restricting the disclosure of information about BSEÓ that robbed those
with
> an interest of any power to react. MP Tony Benn reckons backbench MPs need
a
> Freedom of Information Act as much as anybody, such is the ethos of
secrecy
> around the higher Zchelons of government. But, say disappointed
campaigners,
> this Bill is fairly toothless.
>
> <ENDTEXT>
>
> Any help or suggestions would be very much appreciated.
>
> Thanks in advance
>
> Mario
>
>
------------------------------
Date: Tue, 26 Dec 2000 13:11:04 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: what the hell is wrong with this ??????
Message-Id: <3A489A45.B50B97A2@home.nl>
Ryan wrote:
> #!/usr/bin/perl
>
> print "Content-type: text/html\n\n";
>
> ($seconds, $minutes, $hours, $dayOfMonth, $Month, $year, $dayOfWeek,
> $dayOfYear, $daylSavingTime) = localtime(time);
>
> print "<html><head>";
> print "<title> Punk Radio Cast</title>";
> print "</head><body>";
>
> print $hours, "Hours\n";
> print $minutes, "Minutes\n";
>
this should be : print $hours . ", Hours<br>";
same goes for the minutes.
sinds u are using the html content type u should use the <br> instead of the
\n.
>
> if (($hours >=7) $$ ($hours <=10) $$ ($dayOfWeek = 1) && ($dayOfWeek = 5))
> {
> print "<p>The show is online</p><br>";
> }
> else
> {
> print"<p>Sorry, the shows not on yet</p>";
> }
> print "</body></head>";
>
u already did a </head> earlier, make that </html>.
>
> ive tried this on both a unix/apache, and win98/apache server (changing the
> location of perl each time)
> and it doesnt work, y not?
> someone please help me
> thanks,
> Ryan
------------------------------
Date: Wed, 27 Dec 2000 00:41:41 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: what the hell is wrong with this ??????
Message-Id: <slrn94h80l.8i7.mgjv@martien.heliotrope.home>
On Tue, 26 Dec 2000 13:11:04 GMT,
AvA <a.v.a@home.nl> wrote:
> Ryan wrote:
>
>> print $hours, "Hours\n";
>> print $minutes, "Minutes\n";
>
> this should be : print $hours . ", Hours<br>";
> same goes for the minutes.
> sinds u are using the html content type u should use the <br> instead
> of the \n.
Why? You presume that you know how the OP wants the output formatted.
And if you are going to change the concatenation of those various
strings (which you are doing), why not make it simpler, and do something
like:
print "$hours Hours<BR>";
or even suggest a here-doc?
And how does your 'correction' fix the program? It still won't compile.
As pointed out by others, there's a larger problem somewhere else.
Martien
PS. the second person singular pronoun in English is spelled 'you'.
--
Martien Verbruggen |
Interactive Media Division | I took an IQ test and the results
Commercial Dynamics Pty. Ltd. | were negative.
NSW, Australia |
------------------------------
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 5200
**************************************