[23462] in Perl-Users-Digest
Perl-Users Digest, Issue: 5677 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 17 14:05:56 2003
Date: Fri, 17 Oct 2003 11:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 17 Oct 2003 Volume: 10 Number: 5677
Today's topics:
Re: A New bie's doubt <jwillmore@remove.adelphia.net>
Re: combining regular expressions (Roy Johnson)
Get original destination IP and port with Linux 2.4 ipt <junkto@tm.net.my>
Re: help chdir UNC path ( newbie ) CLOSED <dfraisse@free.fr>
Re: How to generate 2 dimensional array-s? <nobull@mail.com>
Re: Is flock Needed for Logs? <bik.mido@tiscalinet.it>
Re: line to array convertion (Roy Johnson)
Need for a FAQ? (Re: Perl scripts for Unix on my window <jwillmore@remove.adelphia.net>
Re: Need help with "substitute" operator.... <nobull@mail.com>
Re: Perl in Legato AAM (catfish_face)
really hard regex ;( (Thomas)
Re: really hard regex ;( (Anno Siegel)
Re: really hard regex ;( <nobull@mail.com>
regex @a = m / | /g and captures? (Bill)
Re: regex @a = m / | /g and captures? <grazz@pobox.com>
Re: regex @a = m / | /g and captures? (Tad McClellan)
Scope of \Q, \L, \U, etc. <edi@agharta.de>
Re: script removes too many lines <spedwards@qwest.net>
Re: script removes too many lines <spedwards@qwest.net>
Re: script removes too many lines (Tad McClellan)
Re: split operator (NO_SPAM)
Re: Unexpected alteration of array's content (Roy Johnson)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 17 Oct 2003 15:43:59 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: A New bie's doubt
Message-Id: <20031017114425.37b5e829.jwillmore@remove.adelphia.net>
On Fri, 17 Oct 2003 10:40:44 +0200
"Naren" <narendranath.ts1@de.bosch.com> wrote:
<snip>
>
> how can one append a key value pair programmatically.I could not get
> it in a book available here.
type on the command line:
perldoc perl
This is the documentation for Perl. You will find, over time, that
the book is a supplement to the already existing documentation :-)
To answer the original question, type:
perldoc -q hash
It may not provide a direct answer to the direct question, but you may
need it later on.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
It's easier to fight for one's principles than to live up to
them.
------------------------------
Date: 17 Oct 2003 07:09:40 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: combining regular expressions
Message-Id: <3ee08638.0310170609.18eda2b@posting.google.com>
"Kev" <karigna@verizon.net> wrote in message news:<sPIjb.14350$fv4.8095@nwrdny02.gnilink.net>...
> I have two regular expressions that work fine individually but not together
> can I get help to combine them?
>
> ( /(\w[\w'-]*)/g) - I'm using this one to pull words from a text file
>
> /\b\w(3,)\b/g - this one pulls out words of 3 or more characters
>
> K.
Have you been through
perldoc perlretut
? You seem to be a little confused about the purpose of curlies vs.
brackets vs. parentheses.
/(\w{3,})\W*/g
should do what you want.
------------------------------
Date: Fri, 17 Oct 2003 22:19:32 +0800
From: Lincoln Yeoh <junkto@tm.net.my>
Subject: Get original destination IP and port with Linux 2.4 iptables redirect?
Message-Id: <eguvov87258bl2f1ri08hnisl6tinoi1jv@4ax.com>
Hi,
Say I use iptables to redirect tcp connections to my perl proxy
servers. How then do I get the original destination IP address and tcp
port?
On FreeBSD I just use ipfw and fwd and then following works:
$daddr=$client->sockhost;
$dport=$client->sockport;
And then my various proxies work transparently.
But on Linux I'm supposed to use some FD options:
e.g.
getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &dst_addr, &slen)
What's a good way to do this with perl? Working examples would be very
helpful.
I've tried perl's getsockopt but replacing OPTNAME with
SO_ORIGINAL_DST doesn't work - it's not defined.
perl -f getsockopt
getsockopt SOCKET,LEVEL,OPTNAME
I've tried specifying a numerical 80 for OPTNAME but not sure how to
get the address etc.
Thanks,
Link.
------------------------------
Date: Fri, 17 Oct 2003 15:48:51 +0200
From: "Didier FRAISSE" <dfraisse@free.fr>
Subject: Re: help chdir UNC path ( newbie ) CLOSED
Message-Id: <3f8ff2d5$0$226$626a54ce@news.free.fr>
"Didier FRAISSE" <dfraisse@free.fr> a écrit dans le message de
news:3f8e5192$0$20169$626a54ce@news.free.fr...
> i'm trying to convert this small ruby script into perl script
>
> Reporting.rb
> ========
> Dir.chdir('\\\Bureautique\Reporting France')
> system( 'C:\Program Files\Microsoft Office\Office\Excel.exe "Reporting
> France.xls"')
> Dir.chdir('\\\Bureautique\Reporting Export')
> system( 'C:\Program Files\Microsoft Office\Office\Excel.exe "Reporting
> Export.xls"')
>
> Reporting.pl
> ========
> chdir('\\\Bureautique\Reporting France')
> system( 'C:\Program Files\Microsoft Office\Office\Excel.exe "Reporting
> France.xls"')
> chdir('\\\Bureautique\Reporting Export')
> system( 'C:\Program Files\Microsoft Office\Office\Excel.exe "Reporting
> Export.xls"')
>
> but it seems that UNC path are not welcome !!!
> how can i do the same in perl
>
> thanks
> Didier
>
>
Grace to your assistance, i solve my problem easily.
my $Path = '\\\\Bureautique\\Reporting France\\';
my $xlsFile = 'Reporting France.xls';
my $Program = '"C:\\Program Files\\Microsoft Office\\Office\\Excel.exe"';
my $Command = $Program.' "'.$Path.$xlsFile.'"' ;
system( $Command );
no needs of chdir !!
it was just à matter of slashes and quotes and double quote
many thanks for all of you
Didier
------------------------------
Date: 17 Oct 2003 17:02:20 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to generate 2 dimensional array-s?
Message-Id: <u9k773rgxf.fsf@wcl-l.bham.ac.uk>
Brian McCauley <nobull@mail.com> writes:
> Always declare all varables as lexically scoped in the smallest
> applicable scope unless there is some overwhelming reason not to.
>
> This is not perculiar to Perl. It applies to all programing languages
> that have the concept of lexically scoped variables.
What I forgot to mention, is that in Perl, unlike, say, C variables
are reference-counted. This means it is perfectly safe to make a
pointer (reference) to a lexically scoped variable and continue to use
that reference after the variable goes out of scope. When the
variable goes out of scope it becomes unbound from its lexically
scoped name but continues to exist because there is a reference to
it. Next time the lexical scope is entered a new variable is bound to
the lexical name.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 17 Oct 2003 15:22:21 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Is flock Needed for Logs?
Message-Id: <p6pvovg04q3o350q29l4l911hne5coveqi@4ax.com>
On Thu, 16 Oct 2003 12:35:51 +0100, "Alan J. Flavell"
<flavell@ph.gla.ac.uk> wrote:
>[unattributed quote - original poster was Malcolm Dew-Jones:]
>> > My understanding is that a single `write()' of less than a certain (fairly
>> > large) size is supposed to be atomic on unix (and presumably on linux) -
>> > that means atomic relative to other write() calls.
>
>Indeed. A lot of unix-based software appears to rely on the semantics
>of opening for append, and atomically appending a record, without
>using locking. You can't rely on the *sequence* in which asynchronous
>processes write their records, but they don't fragment records and
>they don't damage file structure. There's a great deal of software
>that would go horribly wrong if that stopped working.
I will trust your word and your experience, however, for anyone
interested, here are the results of a test I made (following the idea
of another poster):
corrupt.pl:
#!/usr/bin/perl -l
use strict;
use warnings;
$|++;
unlink 'log.txt';
open my $out1, '>>log.txt' or die $!;
open my $out2, '>>log.txt' or die $!;
my $stop=time+5;
my $count;
while (time<$stop) {
$count++;
print $out1 "out1: $count";
print $out2 "out2: $count";
}
__END__
test.pl:
#!/usr/bin/perl -ln
use strict;
use warnings;
our $n;
++$n, print if !/^out[12]: \d+$/;
END { print "$n/$." }
__END__
An here are the results of './test.pl log.txt' respectively on
Linux[1] and Windows[2]:
report.lnx.txt:
5189/4354160
4445/3845960
5326/4447462
4604/3955650
4186/3669472
report.win.txt:
62/223608
102/247178
86/238094
21/195220
38/210018
I don't think these data are statistically significative, however I
find for the average of the ratios of the given numbers and for the
corresponding standard deviation the following values:
Linux: 1.17e-3, 2.41e-5
Win: 2.64e-4, 1.26e-4
Any comments?
[1] CRUX Linux 1.1, 2.4.21 kernel, perl 5.8.0.
[2] Windows 98, perl 5.8.0 (AS build 806).
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: 17 Oct 2003 07:41:36 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: line to array convertion
Message-Id: <3ee08638.0310170641.547a0492@posting.google.com>
arctan@moonman.com (arctan) wrote in message news:<c6d76a1b.0310161328.7df445bc@posting.google.com>...
> I am facing a problem well beyond my perl skills
You can remedy that by some industrious reading. Both the Llama book
and the Camel book are very readable.
> Thanks alot in advance for any suggestions
There are a lot of ways to do what you want. As you will have noticed
by now, the usual way to explode a string is by splitting on an empty
pattern:
@chars = split(//, $str);
Then you can print the array either by walking it with foreach loop,
or just using join:
print join("\n", @chars), "\n";
Some other fun ways have been suggested, including uses of substr()
and s///; If you figure out why each of them works, you will have
gained quite a bit of Perl understanding.
I don't think anyone has yet said
perl -ne 'print "$&\n" while /./g'
or
perl -ne 'for $i (1..length) { print /(.){$i}/, "\n" }'
(which I don't really recommend, but it might be instructive to study)
or
perl -ne 'for $i (1..length) { print substr($_, $i-1, 1), "\n" }'
or
perl -pe 'for $i (1..length) { substr($_, $i*2-1, 0, "\n") }'
My choice would probably be
perl -ne 'print join("\n", split//), "\n"'
------------------------------
Date: Fri, 17 Oct 2003 15:26:16 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Need for a FAQ? (Re: Perl scripts for Unix on my windows machine)
Message-Id: <20031017112642.2b24b679.jwillmore@remove.adelphia.net>
On Fri, 17 Oct 2003 00:43:59 -0500
tadmc@augustmail.com (Tad McClellan) wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote:
>
> > here's the place to find the FAQ for this
> > group (aka "our social code" you refer to):
> > http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>
>
> Calling it a FAQ when it has only one (seldom asked) question in
> it is a bit of a stretch. :-)
>
> There is no FAQ for clp.misc.
>
> There is a FAQ for Perl (of course).
Can we have a FAQ? It seems to me there _may_ be a need for one.
I suggest this because other newsgroups have one and I have gained
something from the fact they do. I know that Perl has many - which
could be the first fact of the FAQ (ha, ha). I cite one example group
for reference - comp.unix.shell.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
SHIFT TO THE LEFT! SHIFT TO THE RIGHT! POP UP, PUSH DOWN, BYTE,
BYTE, BYTE!
------------------------------
Date: 17 Oct 2003 17:12:49 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Need help with "substitute" operator....
Message-Id: <u9fzhrrgfy.fsf@wcl-l.bham.ac.uk>
Rich Pasco <richp1234@hotmail.com> writes:
> I had asked,
>
> > I am trying to figure out a Perl "substitute" operator which will
> > change any instances of "\*" (that's backslash asterisk) with "*"
> > (an asterisk by itself), and also, if there are any asterisks not
> > preceded by a backslash, delete them and the remaining characters
> > from there to the end of the string.
>
> John W. Krahn wrote:
>
> > $str =~ s/\\(\*)|\*.*/$1/g;
>
> Thanks to all who answered, good ideas all. Actually John's solution
> looks simplest, so I think I may go with that, unless anyone can see
> any potential problems with it.
John's is _shortest_ and _cleverest_ but this doesn't make it the best
if you are optomising for clarity and maintainablity. I stand by my
statement that since the natural way (in human language) to express
what you want is in two steps, then two s/// operators are simpler
than one.
Oh, and John's isn't really the shortest anyhow if you have warnings
enabled (which, of course, you should).
If you have warnings enabled John's becomes:
{
no warnings 'uninitialized';
$str =~ s/\\(\*)|\*.*/$1/g;
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 17 Oct 2003 07:23:11 -0700
From: john_hosie@hotmail.com (catfish_face)
Subject: Re: Perl in Legato AAM
Message-Id: <c6c3280b.0310170623.74122c55@posting.google.com>
Jim,
Thank you for your reply.
Legato AAM is Legato Automated Availability Manager. It is a
high-availability clustering package for the heterogeneous application
environment. To perform automated functions, it utilizes its own
built-in Perl 5.6 interpreter (at least in release 5.0 it is this
level of Perl.) The Perl interpreter has some proprietary functions
that are used for product-specific purposes. This is really cool
stuff, and I was hoping somebodys out there who had gotten as excited
about it as I have might know of a repository. A lot of the things
that are done have to do with checking system performance, checking
for the existance of certain processes, etc. So related administrative
scipts might also be useful and adaptable to the environment.
The environment runs on Windows, Solaris, RH Linux, AIX, and HP-UX,
and, like I said, can be heterogeneous. They use their own Perl so
there are not release issues to contend with.
I have checked with engineers at Legato, and been told they have no
"contributed program library". But I've found that there are often
places on the net where people drop stuff that is highly functional,
even if imperfect at times. I was hoping there was such a thing for
Legato-specific things.
Thanks again for the reply. I hope this clarifies things for you.
James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<20031016001741.34e494ee.jwillmore@remove.adelphia.net>...
> On 15 Oct 2003 11:22:44 -0700
> john_hosie@hotmail.com (catfish_face) wrote:
>
> > Legato AAM has a built-in Perl interpreter for processing rules,
> > triggers, etc. Does anyone know of anyplace where samples are for
> > Perl scripts that might be used with Legato AAM? I'm really trying
> > to see if there is some repository in the sky for this sort of
> > stuff.
>
> Short answer: no.
>
> Long answer: What is AAM? Backup software? If so, have you checked
> out the Legato web site to see if they posted some samples? Or called
> support for further direction? Some vendors put out Perl modules or
> thier own Perl SDK's, but they are totally unsupported (Remedy, I
> think, puts one out, but they tell you straight up that it's a "on
> your own" adventure).
>
> HTH
>
> --
> Jim
------------------------------
Date: 17 Oct 2003 09:50:48 -0700
From: sctommi@gmx.net (Thomas)
Subject: really hard regex ;(
Message-Id: <5a1109df.0310170850.52ab47c7@posting.google.com>
hi community...
i have a hard work with a "really good" regex -
my regex should substitute/insert (in pdf) something like
/V () with my new value...
my regex is working for the first time when i really have /V ()
but second time i substitute only until first ) without checked for a
\\ before the )
s#([^\\]/V\s*\()((\))|(.*?[^\\]?\)))#$1$value)#ms
im totally confused and have no idea where my mistake is in this regex
best regards
Thomas
------------------------------
Date: 17 Oct 2003 17:10:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: really hard regex ;(
Message-Id: <bmp7pa$3vq$1@mamenchi.zrz.TU-Berlin.DE>
Thomas <sctommi@gmx.net> wrote in comp.lang.perl.misc:
> hi community...
> i have a hard work with a "really good" regex -
> my regex should substitute/insert (in pdf) something like
> /V () with my new value...
> my regex is working for the first time when i really have /V ()
> but second time i substitute only until first ) without checked for a
> \\ before the )
>
> s#([^\\]/V\s*\()((\))|(.*?[^\\]?\)))#$1$value)#ms
>
> im totally confused and have no idea where my mistake is in this regex
It appears you are trying to come up with a regex that deals with nested
constructs. Don't. Use a module that deals with such things, like
Text::Balanced.
It may be possible to do this with a regex, but that would involve a
recursive qr// (an obscenity) and is no fun at all.
Anno
------------------------------
Date: 17 Oct 2003 18:21:51 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: really hard regex ;(
Message-Id: <u9vfqnpyog.fsf@wcl-l.bham.ac.uk>
sctommi@gmx.net (Thomas) writes:
> hi community...
> i have a hard work with a "really good" regex -
> my regex should substitute/insert (in pdf) something like
> /V () with my new value...
> my regex is working for the first time when i really have /V ()
> but second time i substitute only until first ) without checked for a
> \\ before the )
>
> s#([^\\]/V\s*\()((\))|(.*?[^\\]?\)))#$1$value)#ms
>
> im totally confused and have no idea where my mistake is in this regex
Well since you do not define "something like" it is impossible to know
what your regex is supposed to match. Without knowing that there's
only so much one can do.
First we can remove some of the () that do nothing.
s#([^\\]/V\s*\()(\)|.*?[^\\]?\))#$1$value)#ms
Then we can observe that the subpattern /.*?[^\\]?/ will match exactly
the same as /.*?/
s#([^\\]/V\s*\()(\)|.*?\))#$1$value)#ms
Next we observe that ')', the only thing matched by the subpattern
/\)/, could also be the 'best' match for /.*?\)/
It follows that /\)|.*?\)/ will simplify to /.*?\)/
s#([^\\]/V\s*\().*?\)#$1$value)#ms
So I've simplified your regex so its easier to see that it does. But
without knowing what it was supposed to do I can't say how to change
it so that it does what you want.
Random shot-in-the-dark. You original mistake was a spurious ? after [^\\]
s#([^\\]/V\s*\()(\)|.*?[^\\]\))#$1$value)#ms
Although I'm usually not a fan of negative look-behind I think this is
a case I would use it.
s#((?<!\\)/V\s*\().*?(?<!\\)\)#$1$value)#ms
I'd also consider using the /x qualifier.
Alternative shot-in-the-dark, see FAQ: Can I use Perl regular
expressions to match balanced text?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 17 Oct 2003 09:02:50 -0700
From: wherrera@lynxview.com (Bill)
Subject: regex @a = m / | /g and captures?
Message-Id: <239ce42f.0310170802.63a5afc2@posting.google.com>
Hello, I've got a regex question.
In the following, the use of () in an 'or' type regex causes @a to
hold both captures, so for each pass through the regex, one capture
and one undef is stored.
Can this be prevented and still use () captures and '|' in the regex?
>>>>>>>>>>>
my $s = '1 2 {3, 3, 3} 4';
my @a = $s =~ m/\{[^\}]+\}|\d/g;
print "\nWithout captures:\n", join "\n", @a;
@a = $s =~ m/(\{[^\}]+\})|(\d)/g;
foreach(@a) { $_ = 'undef' unless $_; }
print "\n\nNow with captures:\n", join "\n", @a;
<<<<<<<<<<<
------------------------------
Date: Fri, 17 Oct 2003 16:39:42 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: regex @a = m / | /g and captures?
Message-Id: <iXUjb.33$PZ1.5@nwrdny03.gnilink.net>
Bill <wherrera@lynxview.com> wrote:
> In the following, the use of () in an 'or' type regex causes @a to
> hold both captures, so for each pass through the regex, one capture
> and one undef is stored.
>
> Can this be prevented and still use () captures and '|' in the regex?
Put the parentheses around the entire expression.
> @a = $s =~ m/(\{[^\}]+\})|(\d)/g;
/( { [^}]+ } | \d )/xg;
But (as you already know) you don't need the parens at all in
this case.
--
Steve
------------------------------
Date: Fri, 17 Oct 2003 11:40:37 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regex @a = m / | /g and captures?
Message-Id: <slrnbp06s5.6f4.tadmc@magna.augustmail.com>
Bill <wherrera@lynxview.com> wrote:
> In the following, the use of () in an 'or' type regex causes @a to
> hold both captures, so for each pass through the regex, one capture
> and one undef is stored.
>
> Can this be prevented and still use () captures and '|' in the regex?
> @a = $s =~ m/(\{[^\}]+\})|(\d)/g;
grep() is handy when you need to filter a list:
my @a = grep defined, $s =~ m/(\{[^\}]+\})|(\d)/g;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Oct 2003 19:28:40 +0200
From: Edi Weitz <edi@agharta.de>
Subject: Scope of \Q, \L, \U, etc.
Message-Id: <87oewfkc3b.fsf@bird.agharta.de>
man perlop says:
\L lowercase till \E
\U uppercase till \E
\E end case modification
\Q quote non-word characters till \E
However, it doesn't seem to be that simple:
edi@bird:~ > perl -le '$a="Aa-"; print "\Q$a\L$a\E$a"'
Aa\-aa\-Aa\-
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\Q$a\E$a"'
aa-aa\-aa-
These two cases seem to imply that it isn't as simple as "till \E" but
that the scopes of these modifiers can be nested - in the first case
the scope of \Q extendes beyond the \E, in the second case the scope
of \L extends beyond the \E.
But not if we replace \Q with \U:
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\Q$a\E$a"'
aa-aa\-aa-
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\U$a\E$a"'
aa-AA-Aa-
Now the \E ends the scope of both \L and \U, the string behind \E
remains unmodified. This makes sense, kind of, because one could argue
that if the scoping rules were as above the result would be something
like
lc($a . uc($a) . $a)
which would be 'aa-aa-aa-', probably not what people expect.
And what about this one?
edi@bird:~ > perl -le '$a="Aa-"; print "\Q$a\L$a\E$a"'
Aa\-aa\-Aa\-
edi@bird:~ > perl -le '$a="Aa-"; print "\U\Q$a\L$a\E$a"'
AA\-aa-Aa-
By placing \U in front of the string the scope of \Q suddenly ends
at \L? How's that?
Am I missing any rules which could explain this behaviour or are we
just looking at implementation bugs?
FWIW, I'm using Perl 5.8.0 but 5.6.1 also behaves like that.
Thanks in advance for your help,
Edi.
------------------------------
Date: Fri, 17 Oct 2003 08:20:48 -0600
From: "Shawn" <spedwards@qwest.net>
Subject: Re: script removes too many lines
Message-Id: <kUSjb.17$S91.14142@news.uswest.net>
Not quite a masterpiece that he passed it off to be?
:)
> > $line =~ s/\|/\|/g ;
All I can say about this line is that it was originally:
> > $line =~ s/\|/\,/g ;
When I changed it the output went from comma delimited to pipe delimited.
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbousii.3i2.tadmc@magna.augustmail.com...
> Shawn <spedwards@qwest.net> wrote:
>
> > Every time the script encounters a line in the report that begins with
the
> > word: Subset
> > I'd like it to skip or leave that line in the file as well as the next 4
> > lines that follows this line.
>
> > Any suggestions would be greatly appreciated. Thanks
>
>
> That is some rather crufty code...
>
>
> > #!/usr/local/bin/perl
>
> use warnings;
> use strict;
>
>
> > if ($#ARGV < 0 ) {
> > print "Usage $0 infile\n";
> > exit(1);
> > }
>
>
> warn "Usage $0 infile\n" unless @ARGV;
>
>
> > open(INFILE,"$infile") || die "Can't open file $infile $!\n";
> ^ ^
> ^ ^ What's wrong with always quoting "$vars"? (a FAQ)
>
>
> my @my_list;
>
>
> > while ($line = <INFILE>) {
>
>
> while (my $line = <INFILE>) {
>
>
> > next if ($line =~/^Last Name/ || $line =~ /\|Service/ );
> > if ($line =~ /\|/) {
> > $next_line = <INFILE>;
>
>
> my $next_line = <INFILE>;
>
>
> > if ($next_line =~ /----/) {
> > push(@my_list,$line)
> > }
> > else {
> > chomp($line);
> > $next_line =~ s/^ +//;
> > $line_plus = $line . $next_line;
> > push(@my_list,$line_plus);
>
>
> push(@my_list, $line . $next_line); # Look Ma! No temp variable!
> or
> push(@my_list, "$line$next_line");
>
>
> > }
> > }
>
> elsif ( $line =~ /^Subset/ ) {
> push @my_list, $line;
> push @my_list, scalar(<INFILE>) for 1..4;
> }
>
>
> [snip]
>
>
> > $line =~ s/\|/\|/g ;
>
>
> Eh?
>
> What would be the purpose of that line of code?
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Fri, 17 Oct 2003 08:21:22 -0600
From: "Shawn" <spedwards@qwest.net>
Subject: Re: script removes too many lines
Message-Id: <7VSjb.20$S91.14260@news.uswest.net>
Damn, your on to us. Now we have change everything!
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnboutqi.t3a.sholden@flexal.cs.usyd.edu.au...
> On Thu, 16 Oct 2003 23:38:42 -0500, Tad McClellan <tadmc@augustmail.com>
wrote:
> > Shawn <spedwards@qwest.net> wrote:
> [snip]
> >
> >> $line =~ s/\|/\|/g ;
> >
> >
> > Eh?
> >
> > What would be the purpose of that line of code?
>
> Maybe all code must include the company logo which is a stylised WW, and
> that seemed like as good a way as any?
>
> --
> Sam Holden
------------------------------
Date: Fri, 17 Oct 2003 11:43:03 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: script removes too many lines
Message-Id: <slrnbp070n.6f4.tadmc@magna.augustmail.com>
Shawn <spedwards@qwest.net> wrote:
>> > $line =~ s/\|/\|/g ;
>
> All I can say about this line is that it was originally:
>> > $line =~ s/\|/\,/g ;
>
> When I changed it the output went from comma delimited to pipe delimited.
It was orignally converting from pipe to comma delimited.
If you want to leave the pipe delimited data pipe delimited,
then just delete that do-nothing line of code.
[snip TOFU, please do not do that anymore]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 17 Oct 2003 10:59:06 -0400
From: "Kris Wempa" <calmincents(NO_SPAM)@yahoo.com>
Subject: Re: split operator
Message-Id: <bmovqo$gtf26@kcweb01.netnews.att.com>
"Benedikt Feldhaus" <software@werthmesstechnik.de> wrote in message
news:bmo3kn$ng4rt$1@ID-119432.news.uni-berlin.de...
> Hi,
>
> I have this line
> "a, b, c, [11, 22, 33], d"
> I want to split this line, not splitting the values in brackets.
> My result should be
> a
> b
> c
> [11, 22, 33]
> d
>
> Any ideas?
>
> Benedikt
>
>
This could be done several different ways. You could limit your first split
to 4 array members by doing:
@array = split(/,/ , $line , 4);
Then, $array[3] would contain " [11, 22, 33] , d" and you could process it
further. Another way to accomplish the same thing is to pre-process the
line and change all of the commas between '[' and ']' to a temporary
delimiter such as a semicolon. Do your original split on the ','. Then
change the semicolons in the elements back to commas. Those are two ideas
that come to mind.
------------------------------
Date: 17 Oct 2003 07:00:09 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Unexpected alteration of array's content
Message-Id: <3ee08638.0310170600.79c98f5d@posting.google.com>
Brian McCauley <nobull@mail.com> wrote in message news:<u91xtdru2w.fsf@wcl-l.bham.ac.uk>...
> I don't see and either one is more or less readble than the
> other. Double quotes are not the only interpolatative context. The
> @{[...]} really comes into it's own in here-docs.
interpolating here-docs *are* a double-quote context, but I see your
point that interspersing them with cat operators would be clunky. My
preference would still be to set some variables before the here-doc,
and simply interpolate the variables. Then you've got symbolic names
instead of magic formulae.
There seems to be a contingent who believe that variables are Bad
Things.
> > > Another is a fix to a misbehaving map or grep. "Oops, it's changing my
> > > array! Let's put @{[ ... ]} around it."
> >
> > This is the best example,
>
> And is indeed the subject of this thread!
No, the subject of the thread is a foreach, which differs from map and
grep in that it doesn't return a list automatically. It is the
possibility that you want to return a modified form of the input
array, without modifying the original, combined with the fact that
you're never going to use the copy directly, that suggests an
anonymous copy.
Even so, as I said, I think the BLOCK form of map, or rewriting the
grep as a foreach would be better (more efficient and clear).
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5677
***************************************