[25409] in Perl-Users-Digest
Perl-Users Digest, Issue: 7654 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 15 14:05:28 2005
Date: Sat, 15 Jan 2005 11:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 15 Jan 2005 Volume: 10 Number: 7654
Today's topics:
[ANNOUNCE] TK::DynaTabFrame 0.20 <dean.arnold@sbcglobal.net>
Re: Adding a delimiter inbetween number characters and <news@chaos-net.de>
Re: Advice please on stripping non-printing characters <usenet@vyznev.invalid>
Re: Array generation <tadmc@augustmail.com>
Re: Array generation <bik.mido@tiscalinet.it>
Re: Array generation <bik.mido@tiscalinet.it>
Re: Array generation <bik.mido@tiscalinet.it>
Re: Array generation <nobull@mail.com>
Re: Array generation <jkeen_via_google@yahoo.com>
Re: convention regarding lexical filehandles <bik.mido@tiscalinet.it>
Re: convention regarding lexical filehandles <bik.mido@tiscalinet.it>
Re: daemonizing a process AND capture stdout, stderr <nobull@mail.com>
Re: Except script error <bik.mido@tiscalinet.it>
Re: Loop through a text file line by line <news@chaos-net.de>
Re: Loop through a text file line by line <bik.mido@tiscalinet.it>
Re: Loop through a text file line by line <bik.mido@tiscalinet.it>
Script Not Returning Value <hx_101@hotmail.com>
Re: Script Not Returning Value <nobull@mail.com>
Re: Script Not Returning Value <jurgenex@hotmail.com>
Re: Store a single character AFTER a match <bik.mido@tiscalinet.it>
system command on Win98 <mikeflan@earthlink.net>
Re: system command on Win98 <usa1@llenroc.ude.invalid>
VB to Perl <dontmewithme@got.it>
Re: VB to Perl <phaylon@dunkelheit.at>
Re: VB to Perl <spamtrap@dot-app.org>
Re: Works great! <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 11 Jan 2005 19:20:03 GMT
From: Dean Arnold <dean.arnold@sbcglobal.net>
Subject: [ANNOUNCE] TK::DynaTabFrame 0.20
Message-Id: <IAD2K9.1trL@zorch.sf-bay.org>
The uploaded file
Tk-DynaTabFrame-0.20.tar.gz
has entered CPAN as
file: $CPAN/authors/id/D/DA/DARNOLD/Tk-DynaTabFrame-0.20.tar.gz
size: 26965 bytes
md5: 192bf71426dc2f19b7178146afb8ca65
No action is required on your part
Request entered by: DARNOLD (Dean Arnold)
Request entered on: Tue, 11 Jan 2005 19:09:23 GMT
Request completed: Tue, 11 Jan 2005 19:10:29 GMT
Changes in Version 0.20:
- added -tabclose option w/ close button in tabs
- added -tabside option to specify tab orientation
- added -image, -label options
- revised demo script
- improved test scripts
- fixed -raisecolor behavior to revert color of
prior raised tab
- fixed "roaming" tab connector frame
- code mods for performance
- added -tabcolor/-backpagecolor,
-raisecolor widget level options
- added -raisecmd attribute to add() to support event callback
- added some Tk::Notebook drop-in compatibility (pagecget(),
pageconfigure(), pages(), raised())
- POD enhancements
- added -textalign
- added -tabrotate
- added flash(), deflash()
Screenshots/POD/tarball available at
http://www.presicient.com/dynatabframe
I've tested on WinXP, AS 5.8.3, Tk804.027 + patches,
and on Linux (Fedora Core 2, Perl 5.8.5, Tk804.027 wo/ patches);
I'd appreciate hearing of other platform tests; its pure perl,
so hopefully testing should be painless.
Regards,
Dean Arnold
Presicient Corp.
------------------------------
Date: 15 Jan 2005 13:12:21 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Adding a delimiter inbetween number characters and letter characters
Message-Id: <slrncui5lo.5d1.news@maki.homeunix.net>
Michele Dondi wrote :
> On 14 Jan 2005 11:42:14 GMT, Martin Kissner <news@chaos-net.de> wrote:
>
>>> perl -pi -e 's/^(\d+)/$1-/' file1 file2...
>>
>>He also wants to join lines with no numbers at the beginning with the
>>preceding line.
>
> Oh, sorry, I hadn't noticed/didn't remember: you have my apologies.
There's no need for that ;)
So this part of your code
---snip---
if (s/^\d+/$&-/) {
print $line;
$line=$_;
} else {
$line .= $_;
}
---snap---
avoids th "lastline madness" which you rightfully criticized in my first
attempt.
Thanks for that clue.
In my second attempt - I repeat it here for your convenience - I tried
a diffrent approach.
[...]
local $/;
my $content = <DATA>;
$content =~ s/\n\D//g;
$content =~ s/(^\d+|\n\d)/$1-/g;
print $content;
[...]
Now I wonder whether there might be a performance penalty when
processing very large files.
I would guess yes; Is that right?
If there is another point of criticism, please let me know.
Martin
--
Epur Si Muove (Gallileo Gallilei)
------------------------------
Date: Sat, 15 Jan 2005 13:36:44 +0200
From: Ilmari Karonen <usenet@vyznev.invalid>
Subject: Re: Advice please on stripping non-printing characters
Message-Id: <slrncui02c.2vf.usenet@boojum.home.vyznev.net>
J Taylor <no@spam.please> kirjoitti 06.01.2005:
>
> I've chosen to strip all but the printable ascii chars (using hex):
>
> $string =~ s/[^\x20-\x7f]/ /g;
>
> This *seems* to work better for my purposes, I'm wondering though if are
> gotchas I'm missing.
"\x7f" is not printable.
--
Ilmari Karonen
To reply by e-mail, please replace ".invalid" with ".net" in address.
------------------------------
Date: Fri, 14 Jan 2005 23:29:58 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Array generation
Message-Id: <slrncuhaim.6g4.tadmc@magna.augustmail.com>
poopdeville@gmail.com <poopdeville@gmail.com> wrote:
> My knowledge of Perl isn't very sophisticated, so I have no idea how to
> implement this use strict stuff.
perldoc strict
might help.
A good approximation is:
1) put: use strict; near the top of your program
2) put "my " in front of the 1st use of each variable in your program
See also:
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 15 Jan 2005 14:42:55 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Array generation
Message-Id: <5f5iu010o039kfnr51mt056tp05miaekgl@4ax.com>
On 14 Jan 2005 16:23:59 -0800, poopdeville@gmail.com wrote:
>@data = (1,2,4,8,16)
>sub RR {
>my $upper = $#_;
>@LOF = min(($_[0], $_[1])) / max(($_[0], $_[1]));
>for $i (1 .. $upper - 1) {
>push @LOF, min($_[$i], $_[$i+1]) / max($_[$i], $_[$i+1]);
>}
>print @LOF, "\n";
>}
>
>RR(@data);
>
>This is giving me the right *form* of answer, but instead of giving me
>the .5.5.5.5 I expect, it's returning 0.510.50.25. Obviously, I've
>misunderstood some convention. :-) Anybody see what's wrong?
I noticed that you've already found what was wrong and that you've
been given good advice.
As a side note I'd like to add that even if generally speaking
factorizing the code through subs is convenient, in this case min()
and max() are likely to do much of the same job (also, function calls
_with_ arguments are somewhat expensive in perl), well unless they
cache their result, which probably would introduce more work than it
would save, taking into account their simplicity.
So, personally I'd do
sub rr {
my ($old, @out)=1;
for (@_) {
my ($n,$m) = $_<$old ? ($_, $old) : ($old, $_);
push @out, $n/$m;
$old=$_;
}
shift @out;
@out;
}
or
sub rr {
my @a=@_;
shift @a;
my @out;
for (@a) {
my ($n,$m)=($_,shift);
($n,$m)=($m,$n) if $n>$m;
push @out, $n/$m;
}
@out;
}
or
sub rr {
map {
my $r=$_[$_]/$_[$_-1];
$r<1 ? $r : 1/$r;
} 1..$#_;
}
or...
Please note, as another side note that while indeed there's nothing
wrong a priori with a sub print()ing something, I used a return() list
instead, which seems more appropriate, IMHO.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 14:42:56 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Array generation
Message-Id: <6aohu0p7hokrsjg8n7ab41eo19f2detni8@4ax.com>
On 14 Jan 2005 18:10:51 -0800, "jl_post@hotmail.com"
<jl_post@hotmail.com> wrote:
>perl -pe "print '| '" program.pl
perl -pe "s/^/| /" program.pl
PS: OK, I realize that yours would most probably be more efficient,
and no, I'm not testing them, for it's not relevant in this case
anyway...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 14:42:57 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Array generation
Message-Id: <947iu0h20nmagd68r4i6ttipu1ua0ehluk@4ax.com>
On 14 Jan 2005 18:30:47 -0800, poopdeville@gmail.com wrote:
>My knowledge of Perl isn't very sophisticated, so I have no idea how to
>implement this use strict stuff. But after this debugging session
My knowledge of Perl isn't very sophisticated either, _but_ I have no
idea what "how to implement this use strict stuff" could mean. Just at
the same time I assure you that no sophisticated knowledge of Perl is
required to C<use strict;> (or to C<use warnings;>). Just read
perldoc strict
HTH,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 14:04:31 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Array generation
Message-Id: <csb7jm$13v$1@sun3.bham.ac.uk>
poopdeville@gmail.com wrote:
> My knowledge of Perl isn't very sophisticated, so I have no idea how to
> implement this use strict stuff.
You've got it backwards. What "use strict" does is disable three
features of Perl that you should not consider using until your knowledge
of perl _is_ sufficiently sophisticated to understand how and when it is
advisable to use these features.
See my diverting rant and argument with one of the leading lights of the
Perl community at:
http://groups-beta.google.com/group/comp.lang.perl.misc/msg/89f307d6b9e83c65
------------------------------
Date: Sat, 15 Jan 2005 14:50:30 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Array generation
Message-Id: <W4aGd.3957$1l2.3594@trndny05>
Brian McCauley wrote:
> poopdeville@gmail.com wrote:
>
>> My knowledge of Perl isn't very sophisticated, so I have no idea how to
>> implement this use strict stuff.
>
>
> You've got it backwards. What "use strict" does is disable three
> features of Perl that you should not consider using until your knowledge
> of perl _is_ sufficiently sophisticated to understand how and when it is
> advisable to use these features.
>
Brian:
I think we need to distinguish between two situations:
1. The point in an introductory-level Perl course at which an
instructor should introduce the use of strictures to the students -- or
the point at which someone teaching herself Perl should start using
strictures consistently.
and
2. What the readers of this Usenet news group expect posters to do to
solve their Perl problems before posting to the list.
People answer Question 1 in various ways which were extensively
discussed in the Feb 2004 thread from which your link comes
(http://groups-beta.google.com/group/comp.lang.perl.misc/msg/be8903f6ca54024c).
(Reviewing that thread, I was surprised to see that even I had staked
out a position, viz., I use Randal's book and introduce warnings and
strictures when he does.) We're never going to come to consensus as to
the one correct answer to this question. TIMTOWTDI.
But as to Question 2: While a lot of beginners post on
comp.lang.perl.misc, it is *not* a beginners' list -- at least not
"beginners" in the sense of people who have not taken the most
elementary steps needed to solve their Perl problems. Here, we expect
people to have done their homework before posting. When I read/respond
to questions on, say, perl-beginners@yahoogroups (a mailing list I
myself used as a beginner), I do not expect everyone to have turned on
'use strict;' before posting. When I read c.l.p.misc, I do.
Jim Keenan
------------------------------
Date: Sat, 15 Jan 2005 14:42:42 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: convention regarding lexical filehandles
Message-Id: <q64iu0tuoqtn682ae81cte2ilvuq90hm39@4ax.com>
On 14 Jan 2005 19:56:52 GMT, Abigail <abigail@abigail.nl> wrote:
>Are you saying that if you use three arg open, and blindly accept
>filenames from third parties to open, you're safe?
Please do not confuse a necessary condition with a sufficient one.
Concisely
A ==> B
does not imply
B ==> A
(it is true, though, that
!B ==> !A
but there are delicate issues in the realm of logic even with this...)
>I don't buy this argument. Blindly accepting filenames to open which
Don't buy it, but I've never tried to sell it to you...
>are handed to you over CGI is a dumb idea to start with. You will have
>to do more than just disabling magic open.
Granted!
Using the two args form of open() leaves a big security hole. Using
the three args form closes _that_ hole. I've never meant to say that
it closes _any_ hole and that one should be content with that and
avoid validating whatever he's passed.
>But if you have fixed all other things, you probably still don't want
>to use magic open. (But people were able to write safe programs before
This is indeed what I meant.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 14:42:50 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: convention regarding lexical filehandles
Message-Id: <lfnhu0d5irl5b2q6tp3ulb9fgst4dske8s@4ax.com>
On 14 Jan 2005 22:43:10 GMT, Abigail <abigail@abigail.nl> wrote:
>And a - is a valid character in most file systems as well. Yet 'rm -r'
>doesn't remove the file. Is rm broken?
rm -- -r
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 13:45:29 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: daemonizing a process AND capture stdout, stderr
Message-Id: <csb6g0$mn$1@sun3.bham.ac.uk>
Gyruss wrote:
> "Brian McCauley" <nobull@mail.com> wrote in message
> news:cs8ut7$shg$2@sun3.bham.ac.uk...
>
>>Am I missing something here? You direct the output to a file and use
>>File::Tail.
>>
>
> To be honest I think that's a little crude.
[ really complex pipe() based solution ]
Does the acronym KISS mean anything to you?
> my($cr, $cw); # child read and write filehandles
You should declare all varialbles as lexically scoped in the smallest
applicable scope unless there's a positive reason for doing. What is
the point of decalaring these variables too early?
> $cr = $fh++;
> $CHILD{$ARG}->{pw} = $fh++;
> pipe($cr, $CHILD{$ARG}->{pw}) or abort 'cr/pw pipe';
> $CHILD{$ARG}->{pr} = $fh++;
> $cw = $fh++;
> pipe($CHILD{$ARG}->{pr}, $cw) or abort 'pr/cw pipe';
I recent perls all this complexity and symbolic refereneces are not
needed - pipe() will autovivify pseudo-anonymous filehandles for you.
pipe(my $cr, $CHILD{$ARG}{pw}) or abort 'cr/pw pipe';
pipe($CHILD{$ARG}{pr}, my $cw) or abort 'pr/cw pipe';
> open(STDIN, "<&$cr") or abort 'STDIN open';
open(STDIN, '<&', $cr ) or abort 'STDIN open';
------------------------------
Date: Sat, 15 Jan 2005 14:42:54 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Except script error
Message-Id: <m45iu0tes30sdv104re0obo4020ann520p@4ax.com>
On Fri, 14 Jan 2005 22:44:09 +0100, ruud <geen@mail.invalid> wrote:
>> Do a favour to yourself and C<use strict;> too. Also C<use warnings;>
>> is better than -w.
>
>Hi Michele, can you look at my new script further in this threat ?
>I think it is better but still no luck after 2 day's google :-(
>I really apreciate your time and knowhow.
Sorry, but the first answer I gave to you had nothing to do
specifically with the module you're using. OTOH in another post you
wrote:
| I changed is a little bit, but still 1 error left:
| Not enough arguments for send at ./p line 10, near ""post\n")"
which seems to be the problem you have _now_. In that case, is that
Perl's send() or a function from Expect.pm? In the latter case you I
don't have any experience with it and you should read its
documentation by yourself. In the former
: perldoc -f send
: send SOCKET,MSG,FLAGS,TO
: send SOCKET,MSG,FLAGS
(I _suspect_ you may be thinking of using some function exported by
Expect.pm whereas you're really calling a Perl internal function with
the wrong number of arguments.)
HTH,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 15 Jan 2005 12:38:38 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Loop through a text file line by line
Message-Id: <slrncui3mg.5d1.news@maki.homeunix.net>
Michele Dondi wrote :
> On 14 Jan 2005 16:16:09 GMT, Martin Kissner <news@chaos-net.de> wrote:
>
>>>>This worked for me.
>>>
>>> So what?!?
>>
>>I was not sure if I have expressed myself correctly so tried to clear
>>up what I meant.
>
> The point is you said more or less "use
>
> while (<>) { #...
>
> if you want to read from _STDIN_". Well, this is plainly false, as
> explained in detail in the document page you have been referred to.
> Specifically you will be reading from STDIN iff at that point @ARGV is
> empty (or $ARGV[0] eq '-').
Thanks for clarifying that.
My intention was to share advice given from an user which was useful to
me.
Sorry for the mismatching explanation.
--
Epur Si Muove (Gallileo Gallilei)
------------------------------
Date: Sat, 15 Jan 2005 14:42:38 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Loop through a text file line by line
Message-Id: <8h2iu015cl8ilamcjurcogjtgonves873v@4ax.com>
On 14 Jan 2005 11:24:03 -0800, toomanyjoes@mail.utexas.edu wrote:
>I'm still having problems opening a file. I looked at the docs and this
>is what I came up with.
>
>open (FILE, "> C:\notes\gen.txt") || die ("error $!\n"); #See note 1
I hope not to repeat (too much) what other have already said as cmt to
this:
(1) better use lexical FHs nowadays,
(2) better use the three args form of open() nowadays[1],
(3) better use mode '<' when you want to _read_ from a file[2],
(4) better use single quotes when no interpolation or escaping is
required[3],
(4') better _not_ try to use filenames containing "exotic" chars like
"\n" under Windows, because they cannot exist there[4],
(5) better use low precedence logical <or> for flow control and then
(6) better (IMHO) avoid unnecessary parentheses, especially since Perl
is so gentle to allow us to do so in the first place.
>while (<FILE>) { #See note 2
>
>s/\<[NR][a\d]\>/ /g #note 3
>
>if (^\w\D\D\s\d+:\d+) #note 4
>
>Note1: Although in all the examples I've looked at the actual file
>reference is always very vague and I have never seen a full path with
>the files extension in the quotes like I have done here.
See above!
>Note2: Here I want to loop through the file, is this correct?
Yes it is.
>Note3: Here I want to find every instance (In the File) of a "<Ra> or a
><N1>(2,3,etc.)" and replace it with nothing (basically remove it)
This is not _exactly_ what your regexp does (it does more!). I'd do
either
s/<(?:Ra|N\d)>//g;
or
s/<Ra>//g;
s/<N\d)>//g;
I _suspect_ that the latter, notwithstanding the fact that it takes
two statements, may be slightly faster. I'm not benchmarking them
anyway.
Also note that you don't need to escape '<' and '>'.
[snip rest]
>Thanks,
>Joe
>
>Martin Kissner wrote:
>> Michele Dondi wrote :
>> > On 14 Jan 2005 10:24:09 GMT, Martin Kissner <news@chaos-net.de>
>wrote:
Please do NOT top-post, it's considered rude and is likely to have a
negative effect -for you, that is- in the long run.
[1] We've recently discovered that at least one respectable and
esteemed Perl hacker doesn't agree on this point, and with reasons
that eventually turned out to be far from trivial. As a general rule,
especially to a newbie like you I'd still recommend what I've written
above.
[2] Or nothing at all if using the two-args form of open().
[3] But please do not take this as a "law". Common sense and practice
should suggest you when using one or the other (or alternative
delimiter for each of them). And even then others' mileage may vary.
[4] Well, I'm not sure about NTFS (don't have it!), but I suspect so.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 14:42:40 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Loop through a text file line by line
Message-Id: <4v3iu054rupva82h7ek8l1m2omo0p10op9@4ax.com>
On 14 Jan 2005 11:25:23 -0800, toomanyjoes@mail.utexas.edu wrote:
>I'm still having problems opening a file. I looked at the docs and this
>is what I came up with.
[snip rest]
Please do not post the same article twice. It's considered rude.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 10:40:32 -0500
From: Digger <hx_101@hotmail.com>
Subject: Script Not Returning Value
Message-Id: <8adiu0dortu4fp8su7iqu4nfjdtclal4s8@4ax.com>
#!/usr/bin/perl -w
#
$ARGV[0] = 'url2.log';
my %status;
while (<>) {
/ (FAILURE|SUCCESS).+?from (.+)/ and $status{$2} = $1;
}
print "URLs whose last status was SUCCESS:\n";
$status{$_} eq 'SUCCESS' and print " $_\n" for sort keys %status;
print "\nURLs whose last status was FAILED:\n";
$status{$_} eq 'FAILURE' and print " $_\n" for sort keys %status;
#
1) The above script prints out url's from a log file with the FAILED
status if and ONLY if further down the log file a SUCCESS is not
found. (so www.234.com ans www.abc.com would be echoed out)
IE:
snip from log file....
[2005-01-04 09:17:59] FAILURE RESPONSE www.123.com
[2005-01-04 09:18:59] SUCCESS RESPONSE www.678.com
[2005-01-04 09:19:59] FAILURE RESPONSE www.234.com
[2005-01-04 09:20:59] FAILURE RESPONSE www.abc.com
[2005-01-04 09:23:59] SUCCESS RESPONSE www.123.com
2) The above script prints out url's from a log file with the SUCCESS
status if and ONLY if further down it did not fail.
(so www.123.com www.123.com)
Anyway I would like to modify this program.
1. I would like instead of printing out the url's I would like it to
spit out a 1 if a FAILURE url is found and not cleared up further down
the file. So I am trying to add the following
print LOGFILE "1" if /FAIL/;
but it's not working..... If the log file has more than one FAILURE
it's printing out many 1's.
Thanks
~
------------------------------
Date: Sat, 15 Jan 2005 17:07:17 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Script Not Returning Value
Message-Id: <csbiaf$65c$1@sun3.bham.ac.uk>
Digger wrote:
> Subject: Script Not Returning Value
I can see no connection between this subject line and the body of your post.
> #!/usr/bin/perl -w
> #
> $ARGV[0] = 'url2.log';
> my %status;
> while (<>) {
> / (FAILURE|SUCCESS).+?from (.+)/ and $status{$2} = $1;
> }
> print "URLs whose last status was SUCCESS:\n";
> $status{$_} eq 'SUCCESS' and print " $_\n" for sort keys %status;
>
> print "\nURLs whose last status was FAILED:\n";
> $status{$_} eq 'FAILURE' and print " $_\n" for sort keys %status;
> #
>
> 1) The above script prints out url's from a log file with the FAILED
> status if and ONLY if further down the log file a SUCCESS is not
> found. (so www.234.com ans www.abc.com would be echoed out)
>
> IE:
> snip from log file....
> [2005-01-04 09:17:59] FAILURE RESPONSE www.123.com
> [2005-01-04 09:18:59] SUCCESS RESPONSE www.678.com
> [2005-01-04 09:19:59] FAILURE RESPONSE www.234.com
> [2005-01-04 09:20:59] FAILURE RESPONSE www.abc.com
> [2005-01-04 09:23:59] SUCCESS RESPONSE www.123.com
>
> 2) The above script prints out url's from a log file with the SUCCESS
> status if and ONLY if further down it did not fail.
> (so www.123.com www.123.com)
>
> Anyway I would like to modify this program.
>
> 1. I would like instead of printing out the url's I would like it to
> spit out a 1 if a FAILURE url is found and not cleared up further down
> the file. So I am trying to add the following
> print LOGFILE "1" if /FAIL/;
> but it's not working..... If the log file has more than one FAILURE
> it's printing out many 1's.
The above script did not open a filehandle LOGFILE thus the above line
would do nothing. So you are telling us that you inserted the above
line in a unspecified position in a script you haven't shown as and it
is not doing what you expect. If the line above is printing more then
one '1' then it was probably in a loop. Take it outside the loop.
Please generate a minmal but complete script that illustrates your
problem and post it here.
This and much other valuable information can be found in the posting
guidelines.
Random shot in the dark:
print LOGFILE "1" if grep /FAIL/, values %status;
------------------------------
Date: Sat, 15 Jan 2005 18:58:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Script Not Returning Value
Message-Id: <HJdGd.280$ul4.195@trnddc01>
Digger wrote:
For a script to return a custom return value you have to use the exit()
function.
I don't see you using it anywhwere in your code.
> #!/usr/bin/perl -w
> #
> $ARGV[0] = 'url2.log';
> my %status;
> while (<>) {
> / (FAILURE|SUCCESS).+?from (.+)/ and $status{$2} = $1;
> }
> print "URLs whose last status was SUCCESS:\n";
> $status{$_} eq 'SUCCESS' and print " $_\n" for sort keys %status;
>
> print "\nURLs whose last status was FAILED:\n";
> $status{$_} eq 'FAILURE' and print " $_\n" for sort keys %status;
> #
jue
------------------------------
Date: Sat, 15 Jan 2005 14:42:59 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Store a single character AFTER a match
Message-Id: <m42iu01c53kheaodimqhtiq6gqd2r4nejj@4ax.com>
On 14 Jan 2005 17:37:22 -0800, toomanyjoes@mail.utexas.edu wrote:
>if (/<nsup>/)
># Then save the character
^^^
^^^
_Which_ charachter?
>open FILE, '<', 'C:\gen.txt' or die "Could not open file. $!";
Incidentally and in addition to other cmts you've been given, even if
this does work, I recommend using forward slashes '/' anyway, for they
will work just as good and getting used to that practice won't impose
you a mind context switch when writing programs for other OSen.
(But, as a side note to the side note, please note that if you want to
write scripts that are _really_ portable then some more care, and the
use of appropriate modules, is required.)
>close FILE;
If you use lexical filehandles you do not need to close() explicitly;
well _generally_ you don't, that is.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 15 Jan 2005 16:18:48 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: system command on Win98
Message-Id: <41E942A4.12AD13A1@earthlink.net>
On Win2000, my scripts that execute another program
with system (or exec) work fine. But when I try the
same scripts on Win98, it gives an error "bad command
or file name" when it hits the system (or exec) command.
I see that others have reported similar problems with
the system command on Win32:
http://perlmonks.thepen.com/104680.html
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/9986?help-en
but I don't see an obvious solution to the problem.
Anybody on this list using Perl on Win98 and know how
to fix this problem? I also see that the shell on Win98
sucks. I need to replace that also.
The command I am using is:
system 'lltost.fch';
Mike Flannigan
------------------------------
Date: Sat, 15 Jan 2005 11:37:41 -0500
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: system command on Win98
Message-Id: <pan.2005.01.15.16.37.10.8454@asu1cornelledu>
In article <41E942A4.12AD13A1@earthlink.net> posted on Sat, 15 Jan 2005
16:18:48 +0000, Mike Flannigan wrote:
> On Win2000, my scripts that execute another program
> with system (or exec) work fine. But when I try the
> same scripts on Win98, it gives an error "bad command
> or file name" when it hits the system (or exec) command.
>
> I see that others have reported similar problems with
> the system command on Win32:
> http://perlmonks.thepen.com/104680.html
What are you talking about? That discussion is entitled "How do I fork a
process under Win 32?"
You mentioned system or exec. The two do different things. Which one is it?
Post a short but complete script others can run. Describe what happens and
what you thought would happen. Read the posting guidelines for this group
for more information on how to post here.
> Anybody on this list
This is not a list.
> using Perl on Win98 and know how to fix this problem?
I do have a Win 98 handy but I have not seen anything here that would
prompt me to turn it on and try and diagnose a problem.
> I also see that the shell on Win98 sucks.
It works.
> The command I am using is:
> system 'lltost.fch';
What on God's Orange Titan is lltost.fch??? Does that file exist? Is that
really an executable? If not, does the associated application exist? If it
does, have you tried
system 'start lltost.fch';
If you have done these things, why are you hiding the information? If
haven't why not?
Sinan
--
A. Sinan Unur
usa1@llenroc.ude.invalid -- remove invalid and
reverse each component for email address.
------------------------------
Date: Sat, 15 Jan 2005 17:52:47 GMT
From: Larry <dontmewithme@got.it>
Subject: VB to Perl
Message-Id: <dontmewithme-EB45C4.18523315012005@twister2.tin.it>
Hi all,
Sorry for gettin back on this question but I wasn't able to go about it!
Below is a chunk of VB code:
[vb]
Private Type WaveInCaps
ManufacturerID As Integer
ProductID As Integer
DriverVersion As Long
ProductName(1 To 32) As Byte
Formats As Long
Channels As Integer
Reserved As Integer
End Type
Dim Caps As WaveInCaps
Call waveInGetDevCaps(0, VarPtr(Caps), Len(Caps))
[/vb]
and I need to that in Perl!!
sorry again!
(I ain't gonna post this anymore)
------------------------------
Date: Sat, 15 Jan 2005 20:33:08 +0100
From: "Robert Sedlacek" <phaylon@dunkelheit.at>
Subject: Re: VB to Perl
Message-Id: <opsknsli2e2n465k@localhost>
Larry wrote:
> and I need to that in Perl!!
What? You haven't said what it does. Shall we learn VB to help you?
p
--
http://www.dunkelheit.at/
------------------------------
Date: Sat, 15 Jan 2005 13:54:19 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: VB to Perl
Message-Id: <fIWdnTQ1Msh9-3TcRVn-tw@adelphia.com>
Larry wrote:
> and I need to that in Perl!!
What have you tried so far? What were the results, and how were they
different from what you expected?
Looks to me like the VB declares a complex data type, declares an instance
of that type, then passes the address and size of that instance to some
function.
To learn about working with complex data types in Perl, have a look at:
perldoc perlreftut
perldoc perldsc
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sat, 15 Jan 2005 14:42:46 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Works great!
Message-Id: <tr4iu0tqeeahfla6rs7nlnpq1l8ii70p14@4ax.com>
On 14 Jan 2005 22:23:26 GMT, Abigail <abigail@abigail.nl> wrote:
>.. I'd use C<$|++> and C<$|--> respectively.
>
>Unless I am producing obfuscated code on purpose, I will never use
>$| ++ or $| --.
[snip]
>I've no idea why $|++ is so popular, and why people keep copying this
>bad behaviour. I suspect cargo cult.
It may well be. Now that I think of it better, if I had to disable and
enable buffering repeatidly, then probably I _wouldn't_ "use C<$|++>
and C<$|--> respectively".
As I must have written in another post in this thread, though, in my
experience (taking aside obfuscated code and golf) I've only disabled
it somewhere near the beginning of the program and not touched it any
more. And in that case I _do_ like C<$|++>: maybe it's cargo cult, but
I find it visually appealing.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
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 V10 Issue 7654
***************************************