[13599] in Perl-Users-Digest
Perl-Users Digest, Issue: 1009 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 6 23:05:30 1999
Date: Wed, 6 Oct 1999 20:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <939265507-v9-i1009@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 6 Oct 1999 Volume: 9 Number: 1009
Today's topics:
Re: (?p{}) was [Re: Backreference in Regex Code Block?] <ltl@rgsun40.viasystems.com>
Re: Counter <andrew.yuen@fujitsu.com.au>
Re: Das GlasPerlenspiel <andrew.yuen@fujitsu.com.au>
Re: Doh! Adding to HASH when reading!?!?!?! <jeffp@crusoe.net>
Re: Doh! Adding to HASH when reading!?!?!?! <ltl@rgsun40.viasystems.com>
fork, reap, sig{CHLD} frank_c4568@my-deja.com
giving a file a variable name <kpmonroe@unity.ncsu.edu>
Re: giving a file a variable name <jkline@one.net>
Re: Help - Perl regular expression question! <ltl@rgsun40.viasystems.com>
Re: Help - Perl regular expression question! (Larry Rosler)
Re: Help - Perl regular expression question! (Larry Rosler)
Re: How do I accomplish /bin/sort -u ... <bwalton@rochester.rr.com>
Re: Ignore this, just testing to see if it works. (Abigail)
Re: inserting new character (Abigail)
It's working now. Thanks! <marc@fearby.com>
Re: libraries "die"ing (Abigail)
Re: Perplexed with newlines while sending mail <butterfingers1@my-deja.com>
Re: Redirecting output to /dev/null (Martien Verbruggen)
Regex question ()
Re: Regex question <bwalton@rochester.rr.com>
Re: To Abigail re: reading current threads (Matthew Bafford)
Re: To Abigail re: reading current threads (Matthew Bafford)
Re: To Abigail re: reading current threads <uri@sysarch.com>
Re: To Abigail re: reading current threads <elaine@chaos.wustl.edu>
Re: To Abigail re: reading current threads <elaine@chaos.wustl.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 7 Oct 1999 02:41:06 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: (?p{}) was [Re: Backreference in Regex Code Block?]
Message-Id: <7th182$gac$1@rguxd.viasystems.com>
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
:>[A complimentary Cc of this posting was sent to lt lindley
:><lee.lindley@bigfoot.com>],
:>who wrote in article <7tgjno$cob$1@rguxd.viasystems.com>:
:>> :> $foo = qr{ < $foo > # Postponed $foo in brackets
:>> :> | # Or nothing
:>> :> }px;
:>>
:>> Is the "Or nothing" required to break out successfully with a valid
:>> match? I suppose without it the last recursive attempt would always
:>> fail, so the match would always return false. But would it ever
:>> be useful to do that? Why not make it smart enough to return
:>> true when the innermost $foo attempt fails?
:>Make *what* smart enough?
Make me smart enough to ask an unambiguous question about a subject
matter that I don't completely understand yet.
This looks like a recursion that continues as long as $foo continues
to match. But $foo has to stop matching at some point. Why make the
fact that $foo must fail eventually cause the entire re to return
false? Make it DWIM. (?p{$foo}) should always return true. Can you
think of any time that it would be useful for it to return false?
The only case that I can think of is on the first (actually, it is
the second) iteration. But if that is all you care about, then you
don't really need the recursive aspects of this thing.
Or do you see a recursion quantifier in the future? Match {0,4}
levels deep?
:>> Maybe this is really a superior syntax. At least this way, you can
:>> give a quantifier to it and avoid the Or nothing.
:>>
:>> $foo = qr{ < (?p{$foo})? > }x;
:>You can do the same with ($foo)?.
Doh!
:>> I can see how this could be useful, but what the heck happens to
:>> backreferences? Recursive backreferences? Could you somehow pass
:>> them back up or would you have to do something with (?{some code}) to
:>> gather them up as they were matched?
:>The "internal" match creates no backreferences. It is absolutely
:>opaque from the point of view of the outer REx: "point" is moved,
:>nothing else happens.
"point" eq pos() ? I assume so. I can see how this opaqueness
restriction helps with the implementation. :-)
:>> $string = '<<<third term>second term>first term>';
:>>
:>> $foo = qr{ < $foo (.+?) >
:>You do not use . with these constructs. Most probably you want
:>something like [^<>].
Of course. I really hate to post code on c.l.p.m without testing
it. Sometimes even when I do test it, my test suite is not
complete. :-)
It will take me a while to digest the rest of this. Thank you
for taking the time to describe it and thank you very much
for your contributions to these Perl enhancements. This
looks like some really cool stuff.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Thu, 7 Oct 1999 12:14:18 +1000
From: "Fujitsu Australia Limited" <andrew.yuen@fujitsu.com.au>
Subject: Re: Counter
Message-Id: <7tgvh1$v0l@newshost.fujitsu.com.au>
Frank de Bot wrote in message <37FA0B7D.161CAE91@xs4all.nl>...
>Maybe if you write your messages in English we could all understand.
http://babelfish.altavista.digital.com/
------------------------------
Date: Thu, 7 Oct 1999 11:48:07 +1000
From: "Fujitsu Australia Limited" <andrew.yuen@fujitsu.com.au>
Subject: Re: Das GlasPerlenspiel
Message-Id: <7tgtvr$ueq@newshost.fujitsu.com.au>
David Cassell wrote in message <37FBB4AF.57D1A7FE@mail.cor.epa.gov>...
>Fujitsu Australia Limited wrote:
>>
>You want rec.arts.tv.mst3k.misc instead of this ng.
Just a gag. I'm guessing you're not a Hesse fan then. It's a mistake to
confuse Hesse with New Age crystal culture and Trekkies. He's not Tolkien.
Sorry to be off topic. This group is called misc, but it appears to be
dedicated to two main topics: Perl programming problems and newbie bashing,
in a ratio of about 40/60. The latter generates by far the longest threads,
especially when they drift off into personal assessments of Abigail.
One of Perl's greatest gifts is the sense of humour in the community.
There's humour built into the language itself.
Would it help if I used smileys? I find they have the opposite effect to
what's intended.
Neale Morison
------------------------------
Date: Wed, 6 Oct 1999 21:08:24 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Doh! Adding to HASH when reading!?!?!?!
Message-Id: <Pine.GSO.4.10.9910062105560.14462-100000@crusoe.crusoe.net>
[posted & mailed]
> $hashkey_array =3D [ keys %{ $hash->{$key} } ];
> # Why the #$@"=A4!"# has 'two' become a new hashkey.
It's called autovivification. The %{ ... } construct makes the content
inside the braces come into existence, as a hash reference.
$foo =3D @{ $bar };
# even though $bar didn't exist before, it does now, as an array ref
--=20
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN
------------------------------
Date: 7 Oct 1999 01:59:29 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: Doh! Adding to HASH when reading!?!?!?!
Message-Id: <7tguq1$fm6$1@rguxd.viasystems.com>
Thomas <skyhigh@intergalactica.com> wrote:
:>This code is just an example that describes
:>a behaviour i can't understand.
:>#!/usr/local/bin/perl -w
:>use strict;
:>use Data::Dumper;
:>my $hashkeys;
:>my $hashkey_array;
:>my $hash = { 'one' => { 'red' => 'cat',
:> 'blue' => 'dog'
:> },
:> 'three' => { 'red' => 'cats',
:> 'white' => 'horses'
:> }
:> };
:>my $key = "two";
:>$hashkey_array = [ keys %{ $hash->{$key} } ];
At this line the dreaded "autovivification" occurs. You told
perl that you expect a hashreference to exist at $hash->{two}
so it created one for you. Most of the time this is exactly
what you want. After all, if you wanted to allocate storage
yourself every time you needed a data structure, you would
use C.
Nice detecive work with data dumper BTW. I use the debugger
myself.
:># Why the #$@"¤!"# has 'two' become a new hashkey.
:># I don't see the logic in this code being an assignment:
:>keys %{ $hash->{$key} }
:># Do you?
Only because I've remembered a wee bit more of the documentation than
you have, or else I learned it the hard way same as you are now.
Considering my history, I probably learned it the hard way. :-)
:># If you do or not, how should i rewrite the row
:>$hashkey_array = [ keys %{ $hash->{$key} } ];
:># so i don't add the key to the $hash if the key
:># doesn't exist.
$hashkey_array = [ keys %{ $hash->{$key} } ] if exists $hash->{$key};
or maybe you need an if/else, but you should get the idea.
You have written sophisticated enough code that I'm going to assume
that you can find all of this in the documentation now that you
know what to look for.
perldoc -f exists # is a definite must read
and then look for the word "autovivification" somewhere. I don't
remember where. grepping in the pod directory will probably
turn up something.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Thu, 07 Oct 1999 02:10:21 GMT
From: frank_c4568@my-deja.com
Subject: fork, reap, sig{CHLD}
Message-Id: <7tgve5$qk5$1@nnrp1.deja.com>
what I want to do is fork off some children processes, then before
exiting the script, check the return value of the children and act on
that data. My code is below. I'm running Solaris 2.6 and Perl
5.005_03, and I've never used fork() before.
Thanks in advance for any help on this!
Frank
#########
#!/usr/local/bin/perl5
use POSIX ":sys_wait_h";
@things = ('one', 'two', 'three', 'four', 'five', 'six');
my ($pid, $list);
foreach $x (@things)
{
if ($pid = fork)
{
# parent here
} else {
# child here
my $y = &lime ($x);
print $y;
exit 0;
}
}
exit;
#################################################
sub lime
{
my $x = shift;
sleep 5;
return "$x\n";
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 06 Oct 1999 15:40:29 -0400
From: Kevin Monroe <kpmonroe@unity.ncsu.edu>
Subject: giving a file a variable name
Message-Id: <37FBA5AD.F6E29325@unity.ncsu.edu>
I am a relatively new to perl and am running into difficulty giving a
file a variable name. What I want to be able to do is take a file,
parse it, remove some data and save the file with the date as part of
the file name. Like so,
#!/usr/local/bin/perl -w
($Second, $Minute, $Hour, $DayOfMonth, $Month, $Year, $WeekDay,
$DayOfYear, $IsDST) = localtime(time);
$RealMonth = $Month +1;
$RealYear = $Year + 1900;
This part works fine as I can have it print out a statement of like
print "$RealMonth/$DayOfMonth/$RealYear";
and it will print out the current date in MM/DD/YYYY format
However this is where my problem begins at
open(ORIG, '/mypath/this_file.txt') || die "Cannot open this_file.txt";
open(NEW, '>/mypath/this_file.\'$RealMonth.$DayOfMonth.$RealYear\'.txt')
|| die "Cannot open this_file.$RealMonth.$DayOfMonth.$RealYear.txt";
@data = <ORIG>;
splice (@data,0,3);
foreach $line(@data){
chop;
print NEW "$line";
}
close (ORIG);
close (NEW);
What happens is it creates a file but does not insert the variable
information, ie the Month,Day,Year into the file name.
Any ideas???
thanks
kevin
------------------------------
Date: Wed, 06 Oct 1999 22:47:41 -0400
From: Joe Kline <jkline@one.net>
To: kpmonroe@unity.ncsu.edu
Subject: Re: giving a file a variable name
Message-Id: <37FC09CD.C36E1EF9@one.net>
[posted and mailed]
Kevin Monroe wrote:
>
> I am a relatively new to perl and am running into difficulty giving a
> file a variable name. What I want to be able to do is take a file,
> parse it, remove some data and save the file with the date as part of
> the file name. Like so,
>
> #!/usr/local/bin/perl -w
>
> ($Second, $Minute, $Hour, $DayOfMonth, $Month, $Year, $WeekDay,
> $DayOfYear, $IsDST) = localtime(time);
>
I personally like:
@date = localtime(time);
This gives us:
> $RealMonth = $Month +1;
$RealMonth = $date[4] + 1;
> $RealYear = $Year + 1900;
$RealYear = $date[5] + 1900;
<SNIP>
> open(ORIG, '/mypath/this_file.txt') || die "Cannot open this_file.txt";
> open(NEW, '>/mypath/this_file.\'$RealMonth.$DayOfMonth.$RealYear\'.txt')
> || die "Cannot open this_file.$RealMonth.$DayOfMonth.$RealYear.txt";
By using single quotes, you aren't letting Perl do any variable
interpolation. I would use a temp variable or two:
my $old_path = '/mypath/this_file';
my $new_path = "$old_path.$RealMonth.$date[3].$RealYear";
open(ORIG, "< $old_path.txt") or die "Can't open $old_path.txt: $!";
open(NEW, "> $new_path.txt") or die "Can't open $old_path.txt: $!";
This is just a quick suggestion.
joe - glad I'm not George Jempty...
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 7 Oct 1999 01:41:16 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: Help - Perl regular expression question!
Message-Id: <7tgtns$fbm$1@rguxd.viasystems.com>
jennyng@my-deja.com wrote:
:>Hi,
Hi Jenny.
:>I've spent days to try to get the following w/ no success. I was
Did you just spend days trying things or were you puzzling through the
available documentation?
:>wondering if anyone knows how to do the following w/ Perl regular
:>expression (or any other way w/ Perl):
:>if (( $pattern in $line ) && ( $pattern in $line is not w/in [bigger
:>pattern] )) {
:> replace $pattern w/ $replacement
:>}
That description sounds ready-made for a "negative lookahead assertion"
and/or "negative lookbehind assertion". These are described in "perlre"
At a shell prompt type:
perldoc perlre
I must admit that it is a daunting manual page, but you have to start
somewhere. Many people recommend Jeffery Friedle's (sp?) book,
Mastering Regular Expressions, but I have not read it and so cannot
comment.
:>Example:
:>$pattern = "bcd";
:>[bigger pattern] is "abcde"
:>$line = "lllbcdlllabcdelllbcd";
:>$replacement = "wyz";
:>The above will change $line to "lllwyzlllabcdelllwyz".
$line =~ s/(?<!a)bcd(?!e)/wyz/g;
But you might need to look out for overlapping patterns in
the general case. Actually, there are all kinds of things
to look out for, but the documentation in perlre will get you
started.
Here is the code I used to test what I just wrote:
#!/usr/lib/lprgs/perl -w
use strict;
my $pattern = "bcd";
my $bigger_pattern = "abcde";
my ($leading_part, $trailing_part) =
($bigger_pattern =~ /^(.*?)$pattern(.*)$/);
# No error checking to see if that matched or that both parts
# contain anything useful.
my $line = "lllbcdlllabcdelllbcd";
my $replacement = "wyz";
$line =~ s/(?<!$leading_part)$pattern(?!$trailing_part)/$replacement/g;
#:>The above will change $line to "lllwyzlllabcdelllwyz".
print $line;
__END__
lllwyzlllabcdelllwyz
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Wed, 6 Oct 1999 18:42:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help - Perl regular expression question!
Message-Id: <MPG.12659a4a1bbd4be998a052@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7tgon1$m3s$1@nnrp1.deja.com> on Thu, 07 Oct 1999 00:15:40
GMT, jennyng@my-deja.com <jennyng@my-deja.com> says...
> I've spent days to try to get the following w/ no success. I was
> wondering if anyone knows how to do the following w/ Perl regular
> expression (or any other way w/ Perl):
>
> if (( $pattern in $line ) && ( $pattern in $line is not w/in [bigger
> pattern] )) {
> replace $pattern w/ $replacement
> }
>
> Example:
> $pattern = "bcd";
> [bigger pattern] is "abcde"
> $line = "lllbcdlllabcdelllbcd";
> $replacement = "wyz";
> The above will change $line to "lllwyzlllabcdelllwyz".
This works, but it feels odd. Perhaps someone can do better. If the
patterns are literal strings, something might be done with a loop over
index() and substr(). In this code, $pattern may include regex
metacharacters, but if there any in $bigger it has better be framed by
\Q and \E, as the literal value is replaced by itself if it matches.
#!/usr/local/bin/perl -w
use strict;
my $pattern = 'bcd';
my $bigger = 'abcde';
$_ = 'lllbcdlllabcdelllbcd';
my $replacement = 'wyz';
#The above will change $line to "lllwyzlllabcdelllwyz".
s/$bigger|($pattern)/defined $1 ? $replacement : $bigger/ego;
print;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 6 Oct 1999 19:21:55 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help - Perl regular expression question!
Message-Id: <MPG.1265a3a129dc8cf898a053@nntp.hpl.hp.com>
In article <MPG.12659a4a1bbd4be998a052@nntp.hpl.hp.com> on Wed, 6 Oct
1999 18:42:08 -0700, Larry Rosler <lr@hpl.hp.com> says...
...
> #!/usr/local/bin/perl -w
> use strict;
>
> my $pattern = 'bcd';
> my $bigger = 'abcde';
> $_ = 'lllbcdlllabcdelllbcd';
> my $replacement = 'wyz';
> #The above will change $line to "lllwyzlllabcdelllwyz".
>
> s/$bigger|($pattern)/defined $1 ? $replacement : $bigger/ego;
>
> print;
Here's a better solution, which works for arbitrary regexes in either
$pattern or $bigger. Now no index/substr solution is possible.
#!/usr/local/bin/perl -w
use strict;
my $pattern = 'b.d';
my $bigger = 'a...e';
$_ = 'lllbcdlllabcdelllbcd';
my $replacement = 'wyz';
#The above will change $line to "lllwyzlllabcdelllwyz".
s/($bigger)|$pattern/defined $1 ? $1 : $replacement/ego;
print;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 06 Oct 1999 22:39:33 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: How do I accomplish /bin/sort -u ...
Message-Id: <37FC07E5.4AB6C6BB@rochester.rr.com>
yvp@chat.austin.ibm.com wrote:
>
> I am trying to find out answer for following question...
>
> In my perl script, I have following three lines:
>
> >$command = "/bin/sort -u < ".$newfile." >> ".$reportfile;
> >printf ( "%s\n", $command );
> >system ( $command );
>
> when the script executes, $command gets evaluated correct,
> but the last line does not execute properly. If I cut&paste
> the output of second line on my shell command, it accomplishes
> the task. I am beginner at perl and can't find how to solve
> this. Can someone please tell me what I am doing wrong here?
> Thanks.
>
Hmm...looks OK to me. What precisely do you think is wrong with
the way it executes? Do you get an error message? If so, what
does it say? If not, what exactly is wrong? Exact details may
get you help; vague statements won't because no one can tell what
is happening. You might also obtain the return code from system
and let us know what it says.
> P.S. If you chose to send by email, send me at
> karigar@yahoo.com.
> --
>
> _______________________________________________________________________________
> Yogesh V. Patel (512) 838-7145 or T/L 678-7145.
> IBM Austin, TX.
--
Bob Walton
------------------------------
Date: 6 Oct 1999 21:35:12 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Ignore this, just testing to see if it works.
Message-Id: <slrn7vo28t.81.abigail@alexandra.delanet.com>
CS (@mdo.net) wrote on MMCCXXVII September MCMXCIII in
<URL:news:9CHK3.1703$eM4.135434@typ11.nn.bcandid.com>:
Ok, I'll ignore you. *plonk*
Abigail
--
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
for (s;s;s;s;s;s;s;s;s;s;s;s)
{s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 6 Oct 1999 21:39:29 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: inserting new character
Message-Id: <slrn7vo2gv.81.abigail@alexandra.delanet.com>
Noira Hadi (r42317@email.sps.mot.com) wrote on MMCCXXVII September
MCMXCIII in <URL:news:37FAEFB9.4A360B14@email.sps.mot.com>:
??
?? I have data as below:
??
?? A
?? B
?? B
?? D
?? A
?? B
?? D
??
?? I format them to have:
??
?? A,B,B,D
?? A,B,D
??
?? The question is how do I format them so that I can have:
??
?? A,B,B,D
?? A,B,C,D
local $" = ",";
my @array;
while (<>) {
chomp;
push @array => "C" if $_ eq "D";
push @array => $_;
print "@array\n" if $_ eq "D";
}
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Thu, 07 Oct 1999 12:21:14 +1000
From: Marc Fearby <marc@fearby.com>
Subject: It's working now. Thanks!
Message-Id: <37FC039A.2B75A22C@fearby.com>
Thanks guys - it's working like a treat, now!
:-)
------------------------------
Date: 6 Oct 1999 21:55:44 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: libraries "die"ing
Message-Id: <slrn7vo3fd.81.abigail@alexandra.delanet.com>
Sam Holden (sholden@pgrad.cs.usyd.edu.au) wrote on MMCCXXVI September
MCMXCIII in <URL:news:slrn7vl418.ni6.sholden@pgrad.cs.usyd.edu.au>:
%% On Tue, 05 Oct 1999 13:18:47 GMT,
%% Benjamin Franz <snowhare@long-lake.nihongo.org> wrote:
%% >In article <OOD5N2inbanE5PHHhLWT3bJCOgf1@4ax.com>,
%% >David Cantrell <NukeEmUp@ThePentagon.com> wrote:
%% >>
%% >>I suspect that modules/libraries dieing is often because the authors
%% >>are aware that programmers frequently don't bother checking return
%% >>values.
%% >
%% >That's why I do it. There is almost never a good result from
%% >ignoring a failure. By dieing or croaking, I usually ensure
%% >that if it is ignored, it was on purpose. How many postings
%% >relating to 'tie' and 'open' FAQs would vanish from this group
%% >if they threw exceptions on failure rather than returning a false
%% >value?
%%
%% Down that path lies python and *shudder* java...
Really? You'd think the only difference between Perl and Java/Python
is the fact the latter two have more support for throwing exceptions,
and that they do it more often?
Code would be easier to write, if for instance open() would die on a
failure. I've never written any code where I don't care whether the open
fails or succeeds, and when I care, I want to exit the program in 98%
of the cases anyway. The few cases I don't want to die and continue to
do something useful, I could have easily put an eval around the open.
It would have been more Perlish for Perl to "do what I mean" and die
on a failure to open, then copying C's behaviour of returning a special
value.
I generally die in my modules because I don't want to come up with any
back up plan if something isn't right. If the caller has a plan B, fine,
use eval.
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Thu, 07 Oct 1999 02:23:17 GMT
From: Graham W. Boyes <butterfingers1@my-deja.com>
Subject: Re: Perplexed with newlines while sending mail
Message-Id: <7th06b$r9e$1@nnrp1.deja.com>
[snip]
> tr/<BR>/\n/; # if this is one of the things you tried
>
> won't do at all what you expected it to. Try it on a
> simple string like:
> "a word and a <BR> and <=> and <<-- some MORE BLOBS !!"
> and you'll see what I mean.
[/snip]
David, thank you very much, I think this has fixed the problem.
:)Graham W. Boyes
--
"The One and Only"
me AT toao DOT net ~ http://www.toao.net
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 07 Oct 1999 01:42:50 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Redirecting output to /dev/null
Message-Id: <uUSK3.297$bM2.16987@nsw.nnrp.telstra.net>
On Wed, 06 Oct 1999 04:04:37 GMT,
Scot Hacker <bounce.waxwing@dnai.com> wrote:
[shell command]
> hey SoundPlay set file of track 0 to file\(filename\) > /dev/null
> So I want to do this from my perl
> script, and I use:
>
> @ControlSP = ("hey", "SoundPlay", "set", "file", "of", "track", \
> "0", "to", "file\($Current\)", ">", "/dev/null");
> system (@ControlSP);
If you use system() with more than one argument, perl will pass the
arguments directly to execvp(2). This means that the shell never gets
to see any of it.
If, however, you pass only one argument to system() and that argument
contains shell metacharacters (like output redirection), perl will
pass the string to the shell. That is what you want, because the
redirection you are using is a shell feature, not an intrinsic
execvp() or perl feature.
my $status =
"hey SoundPlay set file of track 0 to file\\($Current\\) > /dev/null";
(You need double backwhacks, so that the shell actually gets one,
which it needs to escape the brackets. Alternatively you can do
something like:
hey SoundPlay set file of track 0 to 'file($Current)'
which I prefer, but now we're getting off-topic)
However, since the output of the program goes to stdout, and not
stderr, you can also use the backticks or qx():
my $output = qx#hey SoundPlay set file of track 0 to 'file($Current)'#;
print "status: $?, output: $output";
# perldoc -f system
# perldoc perlop
find: /qx/STRING/
# perldoc perlvar
find: $?
Martien
PS. It's a bit unusual for a unix command to need arguments with
brackets. I don't know that util, but are you sure that it's
necessary?
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd. | but mean your mother.
NSW, Australia |
------------------------------
Date: 7 Oct 1999 11:10:04 +0950
From: michaels@packet.obtero.com.au ()
Subject: Regex question
Message-Id: <slrn7vnte7.419.michaels@packet.obtero.com.au>
Hello,
I need to parse a text file and strip off everything before the digits
that end each line, where the lines are like:
blah blah blah = 2
foo bar baz = 1
I also want to turn the = in to a |. So far, I've got:
foreach $line (<INPUT>) {
if ($line =~ "=") {
$line =~ s//|/;
print $line;
};
};
which changes the = to a |. I kinda stumbled onto this...can't
say I know why it's doing the substitution yet.
Try as I might, I can't seem to do a regex that will take the | and
the digits after it, and strip the \n so that the next match isn't placed
on a new line.
Thanks for any clues!
Cheers,
Mike
------------------------------
Date: Wed, 06 Oct 1999 22:30:00 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Regex question
Message-Id: <37FC05A8.25355226@rochester.rr.com>
michaels@packet.obtero.com.au wrote:
>
> Hello,
>
> I need to parse a text file and strip off everything before the digits
> that end each line, where the lines are like:
>
> blah blah blah = 2
> foo bar baz = 1
>
> I also want to turn the = in to a |. So far, I've got:
>
> foreach $line (<INPUT>) {
>
> if ($line =~ "=") {
> $line =~ s//|/;
> print $line;
> };
> };
>
> which changes the = to a |. I kinda stumbled onto this...can't
> say I know why it's doing the substitution yet.
>
> Try as I might, I can't seem to do a regex that will take the | and
> the digits after it, and strip the \n so that the next match isn't placed
> on a new line.
How about:
foreach $line (<>){
chomp $line;
$line=~s/^.*=\s*(\d+)$/|$1/;
print $line;
}
>
> Thanks for any clues!
>
> Cheers,
> Mike
------------------------------
Date: Thu, 07 Oct 1999 01:41:31 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: To Abigail re: reading current threads
Message-Id: <slrn7vntd6.271.*@dragons.duesouth.net>
On 06 Oct 1999 20:42:45 -0400, Uri Guttman <uri@sysarch.com> cut a
telephone line, and tapped the following to comp.lang.perl.misc using
only his tongue:
: who is brown nosing? elaine? you pathetic fool. she will sic HB on you and
HFB
: uri
--Matthew
--
Some more random caps... ;-)
------------------------------
Date: Thu, 07 Oct 1999 01:41:32 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: To Abigail re: reading current threads
Message-Id: <slrn7vntg1.271.*@dragons.duesouth.net>
Once upon a time (Thu, 07 Oct 1999 00:56:22 GMT), George Jempty"
<jb4mt@verbatims.com> was attempting to figure out Ilya's new Perl regex
features, and accidently sent the following to comp.lang.perl.misc:
: OK, I actually will go away, temporarily, and if and when I come back my
: goal is that no one will identify me as the perpetrator of this thread. I
You don't get it, do you?
We don't care WHO you are so much as how you act.
: George Jempty
--Matthew
------------------------------
Date: 06 Oct 1999 21:45:50 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: To Abigail re: reading current threads
Message-Id: <x7emf8osdt.fsf@home.sysarch.com>
>>>>> "MB" == Matthew Bafford <@dragons.duesouth.net> writes:
MB> On 06 Oct 1999 20:42:45 -0400, Uri Guttman <uri@sysarch.com> cut a
MB> telephone line, and tapped the following to comp.lang.perl.misc using
MB> only his tongue:
MB> : who is brown nosing? elaine? you pathetic fool. she will sic HB on you and
i meant HB, not HFB. you don't know who HB is.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Wed, 06 Oct 1999 22:00:10 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: To Abigail re: reading current threads
Message-Id: <37FBFDD1.8A65AD25@chaos.wustl.edu>
George Jempty wrote:
> And in the meantime you have shown yourself to be an
> insufferable brown-nosing hypocrite.
Me? brown-nose Uri? *mWWHAHAHAHAa*
Dude, take a pill or something.
e.
------------------------------
Date: Wed, 06 Oct 1999 22:06:56 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: To Abigail re: reading current threads
Message-Id: <37FBFF66.568B2BC8@chaos.wustl.edu>
Matthew Bafford wrote:
> On 06 Oct 1999 20:42:45 -0400, Uri Guttman <uri@sysarch.com> cut a
> telephone line, and tapped the following to comp.lang.perl.misc using
> only his tongue:
That's cute but a horrific mental image :) I may have to drive through
town centre and see if I can catch him doing this outside of his house.
> : who is brown nosing? elaine? you pathetic fool. she will sic HB on you and
> HFB
No, he was correct. The HFB has a HB or HFD [ HappyFunDog ] who happens
to be ~130 pounds of furry, friendly, drooling St. Bernard love who
carries about 800psi bite :) We throw in the hair and slobber for free :)
e.
------------------------------
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 1009
**************************************