[18923] in Perl-Users-Digest
Perl-Users Digest, Issue: 1118 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 12 14:06:16 2001
Date: Tue, 12 Jun 2001 11:05:14 -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: <992369114-v10-i1118@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 12 Jun 2001 Volume: 10 Number: 1118
Today's topics:
Re: 2-dimensional array into 1 dimensional array? (Bob)
Re: 2-dimensional array into 1 dimensional array? nobull@mail.com
Re: 500 Error <john.imrie@pa.press.net>
<SPAM>Calling all Perls... <news@computerworker.com>
Re: Ack! Newbie still suffering from C-brain! <john.imrie@pa.press.net>
Re: Artificial code blocks <gnarinn@hotmail.com>
Re: Can an lvalue sub also be an rvalue? nobull@mail.com
Re: Can an lvalue sub also be an rvalue? (pt)
CGI apps for AS/400 data (Jamie Ray)
Re: ENV{HTTP_REFERER} in Netscape nobull@mail.com
Re: Excel and Perl (Matthew J. Salerno)
Re: Excel and Perl (Steven M. O'Neill)
Re: Excel and Perl (isterin)
Re: Excel and Perl <bart.lateur@skynet.be>
Re: FAQ 7.16: What's the difference between dynamic a <ren@tivoli.com>
Re: File upload script <john.imrie@pa.press.net>
Foreach Not Behaving Properly (Barry Allwood)
Help with split?vvp <vprasad@americasm01.nt.com>
Re: Help with split?vvp (Rolf Krahl)
Re: Help with split?vvp <bart.lateur@skynet.be>
Re: Help with split?vvp <rsherman@ce.gatech.edu>
Re: Help with split?vvp <ren@tivoli.com>
Re: Help with split?vvp <Kien_Ha@Mitel.COM>
Re: Help with split?vvp <Kien_Ha@Mitel.COM>
Re: Help with split?vvp <godzilla@stomp.stomp.tokyo>
indentify dir <ppi.nospam@searchy.nospam.net>
Re: indentify dir (Rolf Krahl)
Re: indentify dir <mjcarman@home.com>
Re: Matching anything except a string <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Jun 2001 08:49:32 -0700
From: rabell@co.riverside.ca.us (Bob)
Subject: Re: 2-dimensional array into 1 dimensional array?
Message-Id: <107fafaf.0106120749.b4a14cc@posting.google.com>
That did the trick. Thanks to all who responded. :-)
Bob
Philip Newton <pne-news-20010611@newton.digitalspace.net> wrote in message news:<v68aitoph8b213tdgphlokt04u1ocpupjj@4ax.com>...
> On 11 Jun 2001 11:50:55 -0700, rabell@co.riverside.ca.us (Bob) wrote:
>
> > # (Attempt to) grab the contents of "row" 2.
> > @zork = $test_array[2];
>
> $test_array[2] is a reference to an array, not an array. To assign it to
> an array, you need to dereference it:
>
> @zork = @{ $test_array[2] };
>
> > This looks like it should be easy, and I'm probably missing something
> > obvious.
>
> Suggested reading: perldsc, perlreftut, perllol.
>
> Cheers,
> Philip
------------------------------
Date: 12 Jun 2001 17:42:42 +0100
From: nobull@mail.com
Subject: Re: 2-dimensional array into 1 dimensional array?
Message-Id: <u9vgm11wfx.fsf@wcl-l.bham.ac.uk>
Andras Malatinszky <andras@mortgagestats.com> writes:
> > @test_array = (['3rd', '2nd', 'a'],
> > ['3rd', '1st', 'b'],
> > ['3rd', '2nd', 'c'],
> > ['2nd', '1st', 'a'],
> > ['1st', '1st', 'b'],
> > ['1st', '1st', 'a']);
>
> @zork = @{$test_array[2]};
>
> Now @zork == ['3rd', '2nd', 'c']
Typo!
Now @zork == ('3rd', '2nd', 'c')
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 12 Jun 2001 15:15:50 +0100
From: "John Imrie" <john.imrie@pa.press.net>
Subject: Re: 500 Error
Message-Id: <5vpV6.1413$h45.8299@news.uk.colt.net>
dave <usted@cyberspace.org> wrote in message
news:e2c00ae.0106110519.425ad6e4@posting.google.com...
> and run your script from the command line first, and do:
>
> perl -c script.pl
>
> to check the syntax.
>
> dave
And read the Perl FAQ which goes into this in great detail
------------------------------
Date: Tue, 12 Jun 2001 17:01:05 +0100
From: "computerworker" <news@computerworker.com>
Subject: <SPAM>Calling all Perls...
Message-Id: <61rV6.14391$jd1.790088@monolith.news.easynet.net>
You may be able to profit from your knowledge by registering your details on
http://www.computerworker.com - the site for finding people who do
computers.
------------------------------
Date: Tue, 12 Jun 2001 15:19:41 +0100
From: "John Imrie" <john.imrie@pa.press.net>
Subject: Re: Ack! Newbie still suffering from C-brain!
Message-Id: <HypV6.1414$h45.8281@news.uk.colt.net>
Bart Lateur <bart.lateur@skynet.be> wrote in message
news:hggaits6hdck2djvgekj8r2g2qogjv0rqk@4ax.com...
> Tad McClellan wrote:
>
> >>I agree. Most of my foreach-es are spelled "for", especially if I use $_
> >>as the default loop variable.
> >
> >
> >I disagree. I don't like overloading, is slows down comprehension
> >while I resolve which usage it is.
> >
> >I always use "foreach" for the "walk across a list" thingie.
> >
> >I always use "for" for the "three part C-like" thingie.
>
> Comprehension, and the "three part C-like" thingie in one sentence?
> Boing.
>
Of cause I missed out dropping for entirely and rewriting the loop as a map
statement :)
------------------------------
Date: Tue, 12 Jun 2001 13:15:33 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Artificial code blocks
Message-Id: <992351733.3282087771222.gnarinn@hotmail.com>
In article <5644c067.0106120333.63e43d59@posting.google.com>,
Maggie <maggie_black@hotmail.com> wrote with double linefeeds:
>Hello,
>
> I have a friend who writes code like this:
>
>#!/usr/bin/perl -w
>use strict;
>
>{
> my $variable1;
> my $variable2;
>}
>
>{
> my $other_variable;
>}
>
>and so on.
>
>In other words there's never any place in his code which is not a block. I think this
>is bad style, but am unable to find convincing arguments against it. Could someone
>either confirm my doubts about this style or prove me wrong and explain why this is
>a good thing?
>
i imagine rhe blocks contain more stuff apart from my() statements.
what are your arguments against this?
when you have a sequence of discrete code segments that use
lexicals, it can make sense to wrap them in separate blocks, both to
underline the 'separateness', and to limit the scope of the lexicals
as much as possible. this can be specially helpful if the code needs to be
maintained by someone else, or much later.
in my opinion this is a just matter of personal preference, and
there should usually not be any significant efficiency costs to this.
gnari
------------------------------
Date: 12 Jun 2001 17:46:43 +0100
From: nobull@mail.com
Subject: Re: Can an lvalue sub also be an rvalue?
Message-Id: <u9r8wp1w98.fsf@wcl-l.bham.ac.uk>
"John Lin" <johnlin@chttl.com.tw> writes:
> "pt" wrote
> > Can a sub declared with the "lvalue" attribute also be used as a
> > regular (rvalue) sub?
> > $thing_status = status($thing) ; # get thing's status
> > status($thing) = 0 ; # reset thing's status
>
> Your code tells your the answer. Does it compile? Does it work?
John, that is the Godzilla answer.
I think the OP was asking if the fact that it worked was an
implementational artifact or a design feature.
It's a design feature.
As a general rule, in most programming languages, rvalues are a
superset of lvalues.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 12 Jun 2001 10:41:38 -0700
From: mnemotronic@yahoo.com (pt)
Subject: Re: Can an lvalue sub also be an rvalue?
Message-Id: <da662010.0106120941.2069e293@posting.google.com>
"John Lin" <johnlin@chttl.com.tw> wrote in message news:<9g3qbg$s1r@netnews.hinet.net>...
> "pt" wrote
> > Can a sub declared with the "lvalue" attribute also be used as a
> > regular (rvalue) sub?
> > $thing_status = status($thing) ; # get thing's status
> > status($thing) = 0 ; # reset thing's status
>
> Your code tells your the answer. Does it compile? Does it work?
No and No, but that's only because I haven't figured out the
correct syntax, usage, or incantation yet. One or two short examples
would be appreciated. Thanks in advance.
>
> John Lin
------------------------------
Date: Tue, 12 Jun 2001 16:54:27 GMT
From: jrdarkiii@comporium.net (Jamie Ray)
Subject: CGI apps for AS/400 data
Message-Id: <3b2648a6.1029597784@nntp.comporium.net>
Has anyone had any experience writing Perl CGI's (DBD:DB2) for AS/400
data...Specifically, running the app on Linux or Unix and getting at
the data on the AS/400...If anyone would care to share their
experiences I would appreciate it...
Thanks,
Jamie
------------------------------
Date: 12 Jun 2001 17:37:48 +0100
From: nobull@mail.com
Subject: Re: ENV{HTTP_REFERER} in Netscape
Message-Id: <u9wv6h1wo3.fsf@wcl-l.bham.ac.uk>
"Dianne van Dulken" <dianne@dogmac.com> writes:
> I have already posted this to the perl and perl-cgi mailing lists, but
> haven't been able to find a solution
Maybe because this has nothing to do with Perl and very little to do
with CGI. The underlying issue here is a pure HTML/HTTP one.
> <script language="javascript"
> src="https://testserver.com.au/server/cgi-bin/script1.pl">
> The problem is that Netscape isn't giving me a HTTP_REFERER code at all..
> Everyone I have talked to agrees that it SHOULD be giving it to me, but in
> none of our tests it has done so.
So, if you think you have found a bug in Netscape, submit a bug report
to Netscape.
> Has anyone got a suggestion of what else I could use?
Append a QUERY_STRING and/or PATH_INFO to the SRC= attribute.
> The javascript http_referrer still works in Netscape, but not the
> perl version.
I don't think you are comparing like with like here. I think you mean
client side script v. server side script not Javascript v. Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 12 Jun 2001 06:27:51 -0700
From: msalerno@my-deja.com (Matthew J. Salerno)
Subject: Re: Excel and Perl
Message-Id: <6622f4b.0106120527.677290f@posting.google.com>
Philip Newton <pne-news-20010612@newton.digitalspace.net> wrote in message news:<qflbit0r5n7vmc0fmi7lqj8iqlvnhtl0vo@4ax.com>...
> On Tue, 12 Jun 2001 10:39:40 +0200, David Hiskiyahu
> <David.Hiskiyahu@alcatel.be> wrote:
>
> > Can anyone recommend a module that could help
> > manipulate Excel files from a Perl program?
>
> Win32::OLE
>
> Cheers,
> Philip
Also, you can setup an ODBC connection to the document. I know that
there are plenty of modules you can use, check out DBI. Search at
CPAN.
Enjoy,
Matt
------------------------------
Date: 12 Jun 2001 13:33:17 GMT
From: steveo@panix.com (Steven M. O'Neill)
Subject: Re: Excel and Perl
Message-Id: <9g55mt$nig$1@news.panix.com>
Matthew J. Salerno <msalerno@my-deja.com> wrote:
>Philip Newton <pne-news-20010612@newton.digitalspace.net> wrote in
>message news:<qflbit0r5n7vmc0fmi7lqj8iqlvnhtl0vo@4ax.com>...
>> On Tue, 12 Jun 2001 10:39:40 +0200, David Hiskiyahu
>> <David.Hiskiyahu@alcatel.be> wrote:
>>
>> > Can anyone recommend a module that could help
>> > manipulate Excel files from a Perl program?
>>
>> Win32::OLE
>>
>> Cheers,
>> Philip
>
>Also, you can setup an ODBC connection to the document. I know that
>there are plenty of modules you can use, check out DBI. Search at
>CPAN.
http://support.microsoft.com/support/kb/articles/Q214/7/97.asp
"HOWTO: Automate Excel Using Perl for Win32"
--
Steven O'Neill steveo@panix.com
www.cars-suck.org
------------------------------
Date: 12 Jun 2001 07:55:17 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: Excel and Perl
Message-Id: <db67a7f3.0106120655.558f76ea@posting.google.com>
David Hiskiyahu <David.Hiskiyahu@alcatel.be> wrote in message news:<3B25D54B.B8E52C84@alcatel.be>...
> Can anyone recommend a module that could help
> manipulate Excel files from a Perl program?
Spreadsheet::ParseExcel and Spreadsheet::WriteExcel both cross
platform, you can even manipulate binary excel files on Unix/Linux,
etc...
Can't believe nobody recommended this.
Ilya
------------------------------
Date: Tue, 12 Jun 2001 15:02:18 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Excel and Perl
Message-Id: <66bcitguqc7lhbqd7phcco937dkp3rvflc@4ax.com>
David Hiskiyahu wrote:
>Can anyone recommend a module that could help
>manipulate Excel files from a Perl program?
Using Excel: Win32::OLE. There are afew decent introductions on the web,
including the Win32::OLE FAQ at
<http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/faq/Windows/ActivePerl-Winfaq12.html>
If you want to read an Excel file, *without* any help of Excel itself,
look into SpreadSheet::ParseExcel. Apart from the Unicode modules, the
entire thing is in pure Perl. To generate an Excel file, there's
SpreadSheet::WriteExcel. Both can be found at CPAN,
<http://search.cpan.org>.
--
Bart.
------------------------------
Date: 12 Jun 2001 10:11:46 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: FAQ 7.16: What's the difference between dynamic and lexical (static) scoping? Between local() and my()?
Message-Id: <m38zixn365.fsf@dhcp9-173.support.tivoli.com>
On Tue, 12 Jun 2001, johnlin@chttl.com.tw wrote:
> I don't know whether the following is a good example,
> or it shows my misunderstanding:
>
> sub foo { my $x; \$x }
> print foo,"\n" for 1..3;
> __END__
> SCALAR(0x1be2450)
> SCALAR(0x1bef17c)
> SCALAR(0x1be2450)
Well, returning a reference to a lexical is going to bump up the ref
count, which will necessitate an additional allocation. It is
interesting that the third iteration reuses the initial value -- or
perhaps it is more interesting that the second doesn't.
What I find even more strange is the difference between:
sub foo { my $x; print \$x, "\n"; }
foo for 1..3;
__END__
SCALAR(0x8104e54)
SCALAR(0x8104ecc)
SCALAR(0x8104df4)
and
sub foo { my $x; print \$x, "\n"; 1 }
foo for 1..3;
__END__
SCALAR(0x8104e54)
SCALAR(0x8104e54)
SCALAR(0x8104e54)
The third example makes sense, but the second one doesn't.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 12 Jun 2001 16:01:53 +0100
From: "John Imrie" <john.imrie@pa.press.net>
Subject: Re: File upload script
Message-Id: <haqV6.1415$h45.8341@news.uk.colt.net>
Esteban <egiron@gmx.net> wrote in message
news:2bcb382b.0106110621.430cd88d@posting.google.com...
> I'm having trouble with a file upload script which uses cgi-lib.pl,
> anyone interested in giving a hand, please reply.
I suggest moving to CGI.pm
------------------------------
Date: 12 Jun 2001 18:01:29 GMT
From: barryallwood@aol.com (Barry Allwood)
Subject: Foreach Not Behaving Properly
Message-Id: <20010612140129.02648.00004188@ng-fa1.aol.com>
Hey,
I am making a news script not to similar to newspro and I was wondering why
when I use 2 foreach loops to display news I get an extra box
(http://www.sky-scraper.net/phoenix/bpnews2.cgi) at the bottom, here is the
code if you need it
#!/usr/bin/perl
require "bpcs.pl";
print "Content-type: text/html\n\n";
&Parse(\%in);
$AID = $in{'AID'};
open (NEWS, "< news.txt") or &die("crappy shit");
@article = <NEWS>;
close (NEWS);
foreach (@article) {
my ($NewsAID, $NewsTitle, $NewsText, $NewsPerson, $NewsDate, $Display, $Bump) =
split /:x:/;
&NewsTemplate(@article) if (($AID == '') && ($Display == 0)) && ($Bump == 1);
}
foreach (@article) {
my ($NewsAID, $NewsTitle, $NewsText, $NewsPerson, $NewsDate, $Display, $Bump) =
split /:x:/;
if ($AID == $NewsAID) {
#Print The Returned Article
&NewsTemplate(@article) unless ($Display == 1);
} elsif ($AID != $NewsAID) {
#Do Nothing, It Does Not Return A Value
}
#Print All Of The Articles if There is no submission in the AID
&NewsTemplate(@article) if (($AID == '') && ($Display == 0)) && ($Bump == 0);
}
Thanks,
Barry Allwood (Creating The News Script BackPage)
------------------------------
Date: Tue, 12 Jun 2001 10:38:55 -0400
From: "Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com>
Subject: Help with split?vvp
Message-Id: <3B26297F.9BB8F76A@americasm01.nt.com>
Hello,
I have a small script that takes a PIPE ( | ) delimited file that is
suppose to strip the first field away, replace it with a 0 then keep the
rest of the | delimited fields.
ie.
file (many lines)
a|b|c|d|e|f|g
output to new file should be
0|b|c|d|e|f|g
what happens...the file contains this
0|2
I have to use a PIPE (|) - because that is the standard for all our
files.
Script:
open (rf,"$filename");
open (faxtemp,">$filename.txt");
while($line=<rf>) {
($a,$items)=split /|/,$line;
print faxtemp "0|$items \n";
}
close (rf);
help?
Thanks,
V
------------------------------
Date: 12 Jun 2001 15:18:10 GMT
From: rolf.krahl@gmx.net (Rolf Krahl)
Subject: Re: Help with split?vvp
Message-Id: <9g5bri$b6j$2@kohl.informatik.uni-bremen.de>
In article <3B26297F.9BB8F76A@americasm01.nt.com>,
"Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> writes:
> Hello,
>
> I have a small script that takes a PIPE ( | ) delimited file that is
> suppose to strip the first field away, replace it with a 0 then keep the
> rest of the | delimited fields.
>
> Script:
>
> open (rf,"$filename");
>
> open (faxtemp,">$filename.txt");
> while($line=<rf>) {
> ($a,$items)=split /|/,$line;
> print faxtemp "0|$items \n";
>
> }
> close (rf);
First remark, you must escape the '|' in the pattern, since it is a
regexp special character.
But then, it still won't work. Just look what your script actually
does: it takes the line, split it along the '|' and then, it takes the
first two elements of the resulting list and writes those two back in
the new file. Of corse, you get a result with just two elements per
line.
What you wanted to do is:
| open (rf,"$filename");
|
| open (faxtemp,">$filename.txt");
| while($line=<rf>) {
| ($a, @items) = split /\|/, $line;
| print faxtemp join("|", (0, @items));
|
| }
| close (rf);
Mind the difference between $items and @items. (No "\n" in the print,
since it is still there sitting in the last element.)
But since TIMTOWTDI, you could also do this:
| open (rf,"$filename");
|
| open (faxtemp,">$filename.txt");
| while($line=<rf>) {
| $line =~ s/^[^|]+/0/;
| print faxtemp $line;
| }
| close (rf);
--
Rolf Krahl <rolf.krahl@gmx.net>
------------------------------
Date: Tue, 12 Jun 2001 15:23:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help with split?vvp
Message-Id: <stccitg1dn0n457icj0jn9h7it12d0sm7c@4ax.com>
Prasad, Victor [FITZ:K500:EXCH] wrote:
>file (many lines)
>
>a|b|c|d|e|f|g
>
>output to new file should be
>
>0|b|c|d|e|f|g
Simplest solution:
s/^[^|]*/0/;
>while($line=<rf>) {
> ($a,$items)=split /|/,$line;
> print faxtemp "0|$items \n";
>}
Two errors.
A) escape the pipe. It is special in regexes.
B) Set a limit for split(), or you'll loose everything from the 3rd item
on.
($a, $items) = split /\|/, $line, 2;
--
Bart.
------------------------------
Date: Tue, 12 Jun 2001 11:50:24 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Help with split?vvp
Message-Id: <3B25BBB0.5F27E5E9@ce.gatech.edu>
"Prasad, Victor [FITZ:K500:EXCH]" wrote:
> Hello,
>
> I have a small script that takes a PIPE ( | ) delimited file that is
> suppose to strip the first field away, replace it with a 0 then keep the
> rest of the | delimited fields.
>
> ie.
>
> file (many lines)
>
> a|b|c|d|e|f|g
>
> output to new file should be
>
> 0|b|c|d|e|f|g
>
> what happens...the file contains this
>
> 0|2
>
> I have to use a PIPE (|) - because that is the standard for all our
> files.
>
> Script:
>
> open (rf,"$filename");
>
> open (faxtemp,">$filename.txt");
> while($line=<rf>) {
> ($a,$items)=split /|/,$line;
> print faxtemp "0|$items \n";
>
> }
> close (rf);
>
> help?
>
> Thanks,
>
> V
while (<rf>){
@array = split /|/,$_;
shift @array;
$items = join "",@array;
print faxtemp "0" . "$items";
}
------------------------------
Date: 12 Jun 2001 10:41:55 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Help with split?vvp
Message-Id: <m3y9qxln7g.fsf@dhcp9-173.support.tivoli.com>
On Tue, 12 Jun 2001, vprasad@americasm01.nt.com wrote:
[snip]
> a|b|c|d|e|f|g
>
> output to new file should be
>
> 0|b|c|d|e|f|g
>
> what happens...the file contains this
>
> 0|2
>
> I have to use a PIPE (|) - because that is the standard for all our
> files.
>
> Script:
>
> open (rf,"$filename");
>
> open (faxtemp,">$filename.txt");
> while($line=<rf>) {
> ($a,$items)=split /|/,$line;
Two problems here. First, "|" is special in a regex, so you need to
escape it ("\|"). Second, it looks like you want all of the rest of
the items to be left alone. To achieve this, you need to pass a third
argument to split telling it to only split the string in two:
($a,$items) = split /\|/, $line, 2;
> print faxtemp "0|$items \n";
>
> }
> close (rf);
That should fix the problem. An additional issue with your script is
that you should always (yes, always) check the return value from
open. Also, filehandles are normally in uppercase.
open RF, $filename or die "Could not open $filename, $!";
open FAXTEMP, ">$filename.txt"
or die "Could not create $filename.txt, $!";
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 12 Jun 2001 13:21:50 -0400
From: Kien Ha <Kien_Ha@Mitel.COM>
Subject: Re: Help with split?vvp
Message-Id: <3B264FAE.E4C345BD@Mitel.COM>
"Prasad, Victor [FITZ:K500:EXCH]" wrote:
>
> Hello,
>
> I have a small script that takes a PIPE ( | ) delimited file that is
> suppose to strip the first field away, replace it with a 0 then keep the
> rest of the | delimited fields.
>
> ie.
>
> file (many lines)
>
> a|b|c|d|e|f|g
>
> output to new file should be
>
> 0|b|c|d|e|f|g
>
> what happens...the file contains this
>
> 0|2
>
> I have to use a PIPE (|) - because that is the standard for all our
> files.
>
> Script:
>
Should check the open status:
> open (rf,"$filename")
or die "Can't open $filename for read. $!";
>
> open (faxtemp,">$filename.txt")
or die "Can't open $filename.txt for write. $!";
> while($line=<rf>) {
> ($a,$items)=split /|/,$line;
(undef, $items) = split /\|/, $line, 2;
> print faxtemp "0|$items \n";
print faxtemp '0' . $items;
>
> }
> close (rf);
>
> help?
>
> Thanks,
>
> V
One liner:
perl -i.bak -lpwe 's/^[^|]*/0/;' filename
------------------------------
Date: Tue, 12 Jun 2001 13:32:47 -0400
From: Kien Ha <Kien_Ha@Mitel.COM>
Subject: Re: Help with split?vvp
Message-Id: <3B26523F.264D8BDC@Mitel.COM>
Kien Ha wrote:
>
> "Prasad, Victor [FITZ:K500:EXCH]" wrote:
> >
> > Hello,
> >
> > I have a small script that takes a PIPE ( | ) delimited file that is
> > suppose to strip the first field away, replace it with a 0 then keep the
> > rest of the | delimited fields.
> >
> > ie.
> >
> > file (many lines)
> >
> > a|b|c|d|e|f|g
> >
> > output to new file should be
> >
> > 0|b|c|d|e|f|g
> >
> > what happens...the file contains this
> >
> > 0|2
> >
> > I have to use a PIPE (|) - because that is the standard for all our
> > files.
> >
> > Script:
> >
>
> Should check the open status:
> > open (rf,"$filename")
> or die "Can't open $filename for read. $!";
>
> >
> > open (faxtemp,">$filename.txt")
> or die "Can't open $filename.txt for write. $!";
>
> > while($line=<rf>) {
> > ($a,$items)=split /|/,$line;
> (undef, $items) = split /\|/, $line, 2;
>
> > print faxtemp "0|$items \n";
> print faxtemp '0' . $items;
Sorry. Should be print faxtemp '0|' . $items;
or print faxtemp "0|$items";
> >
> > }
> > close (rf);
> >
> > help?
> >
> > Thanks,
> >
> > V
>
> One liner:
> perl -i.bak -lpwe 's/^[^|]*/0/;' filename
------------------------------
Date: Tue, 12 Jun 2001 10:45:17 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Help with split?vvp
Message-Id: <3B26552D.3603F6BA@stomp.stomp.tokyo>
Prasad, Victor wrote:
(snipped)
> I have a small script that takes a PIPE ( | ) delimited file...
Never use metacharacters for delimiters. This is
a sure invitation to experience problems later.
> a|b|c|d|e|f|g
> output to new file should be
> 0|b|c|d|e|f|g
I have copied out and tested a variety of methods
posted. You will do well to always test code before
posting and, you will do well to always test posted
code before use.
You will discover only my code works correctly simply
as a result of testing my code before posting.
Typically, files are terminated with a newline, yes?
Godzilla!
__
CONTENTS OF test.txt:
_____________________
a|b|c|d|e|f|g
h|i|j|k|l|m|n
o|p|q|r|s|t|u
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
print "\n\nMy Method:\n\n";
open (FILEHANDLE, "test.txt");
while (<FILEHANDLE>)
{
if ($_ ne "\n")
{
substr ($_, 0, index ($_, "\|"), "0");
print $_;
}
}
close (FILEHANDLE);
print "\n\nNext Method:\n\n";
open (FILEHANDLE, "test.txt");
while (<FILEHANDLE>)
{
$_ =~ s/^[^|]*/0/;
print $_;
}
close (FILEHANDLE);
print "\n\nNext Method:\n\n";
open (FILEHANDLE, "test.txt");
while(<FILEHANDLE>)
{
($a, @items) = split /\|/, $_;
print join("|", (0, @items));
}
close (FILEHANDLE);
print "\n\nNext Method:\n\n";
open (FILEHANDLE, "test.txt");
while(<FILEHANDLE>)
{
($a,$items) = split /\|/, $_, 2;
print "0|$items \n";
}
close (FILEHANDLE);
print "\n\nNext Method:\n\n";
open (FILEHANDLE, "test.txt");
while(<FILEHANDLE>)
{
(undef, $items) = split /\|/, $_, 2;
print '0' . $items;
}
close (FILEHANDLE);
exit;
PRINTED RESULTS:
________________
My Method:
0|b|c|d|e|f|g
0|i|j|k|l|m|n
0|p|q|r|s|t|u
Next Method:
0|b|c|d|e|f|g
0|i|j|k|l|m|n
0|p|q|r|s|t|u
0
Next Method:
0|b|c|d|e|f|g
0|i|j|k|l|m|n
0|p|q|r|s|t|u
0
Next Method:
0|b|c|d|e|f|g
0|i|j|k|l|m|n
0|p|q|r|s|t|u
0|
Next Method:
0b|c|d|e|f|g
0i|j|k|l|m|n
0p|q|r|s|t|u
0
------------------------------
Date: Tue, 12 Jun 2001 16:40:10 +0200
From: Frank de Bot <ppi.nospam@searchy.nospam.net>
Subject: indentify dir
Message-Id: <3b2629ca$0$21089$e4fe514c@newszilla.xs4all.nl>
Hi,
I have this little piece of code:
foreach $file(@somearray) {
open(INFILE, "$dir/$file") || print "$! for $dir/$file\n";
($device, $irn, $fileInfo, $links, $userID, $groupID, $deviceID,
$size,$access, $modify, $inrChange, $preferredIO, $IO) = stat(INFILE);
close(INFILE);
}
@somearray could contain files or sub-dirs. The rest is to find out what i
could be. I'm trying to indentify the dirs by checking if $links > =2 . But
this doesn't always works quite good. This is mainly by smb shares (you may
call this windows network environment).
Is there a way to check if the item in @somearray is a file or directory no
matter what filesystem it's looking on?
Thanks in advanced,
Frank de Bot!
------------------------------
Date: 12 Jun 2001 15:27:15 GMT
From: rolf.krahl@gmx.net (Rolf Krahl)
Subject: Re: indentify dir
Message-Id: <9g5ccj$b6j$3@kohl.informatik.uni-bremen.de>
In article <3b2629ca$0$21089$e4fe514c@newszilla.xs4all.nl>,
Frank de Bot <ppi.nospam@searchy.nospam.net> writes:
>
> Is there a way to check if the item in @somearray is a file or
> directory no matter what filesystem it's looking on?
I have no idea about smb shares, but why don't you just use the '-f'
and '-d' file test operators:
| print "$dir/$file is an ordinary file\n" if -f "$dir/$file";
| print "$dir/$file is a directory\n" if -d "$dir/$file";
--
Rolf Krahl <rolf.krahl@gmx.net>
------------------------------
Date: Tue, 12 Jun 2001 10:16:30 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: indentify dir
Message-Id: <3B26324E.5C343EC8@home.com>
Frank de Bot wrote:
>
> Is there a way to check if the item in @somearray is a file or
> directory no matter what filesystem it's looking on?
Use -d to test it:
if (-d $file) {
# It's a directory
}
There are numerous other file tests; see the perlfunc manpage for the
details.
-mjc
------------------------------
Date: Tue, 12 Jun 2001 08:02:10 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Matching anything except a string
Message-Id: <3b262ef3$1@news.microsoft.com>
"Christopher Kleinheitz" <c-kleinheitz@freenet.de> wrote in message
news:3B21CA52.2E24D1BD@freenet.de...
> I'm a perl newbie and want to filter out a table from a html-page using
> $html=~m|(<table[^</table]*</table>)|i;
> I know that it cant' work because [^</table] is a word class. How can I
> match anything except "</table"?
In short: forget it and use HTML::Parser instead.
jue
------------------------------
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 1118
***************************************