[16157] in Perl-Users-Digest
Perl-Users Digest, Issue: 3569 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 16:53:08 2000
Date: Mon, 10 Jul 2000 13:52:53 -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: <963262373-v9-i3569@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 10 Jul 2000 Volume: 9 Number: 3569
Today's topics:
Hope this is the right group <ZXCYE@SAMBAABMAS.GRO>
Re: Hope this is the right group (Bart Lateur)
Re: Hope this is the right group <ZXCYE@SAMBAABMAS.GRO>
Re: Hope this is the right group (Tad McClellan)
Re: Hope this is the right group (Abigail)
How can i know when a string == NULL <abel@inlander.es>
Re: How can i know when a string == NULL <mike.solomon@eps.ltd.uk>
Re: How can i know when a string == NULL (Bart Lateur)
how can I merge data from two text files into an excell <wedeking@msa.attmil.ne.jp>
Re: how can I merge data from two text files into an ex (Bart Lateur)
Re: how can I merge data from two text files into an ex (Tad McClellan)
How dat werk? Re: Delayed HTML Output in PERL (Gwyn Judd)
Re: How dat werk? Re: Delayed HTML Output in PERL <thunderbear@bigfoot.com>
How do I get rid of unwanted newlines when I print an a (David Bell)
Re: How do I get rid of unwanted newlines when I print (Bernard El-Hagin)
Re: How do I get rid of unwanted newlines when I print (Rafael Garcia-Suarez)
Re: How do I get rid of unwanted newlines when I print <adetalabi@clara.co.uk>
Re: How do I get rid of unwanted newlines when I print dharkael@my-deja.com
Re: How do I get rid of unwanted newlines when I print (Tad McClellan)
Re: How do I get rid of unwanted newlines when I print (Tad McClellan)
Re: How do I get rid of unwanted newlines when I print <aqumsieh@hyperchip.com>
Re: How do I get rid of unwanted newlines when I print (Tad McClellan)
Re: How do I get rid of unwanted newlines when I print (David Bell)
Re: How do I split multi line strings in perl <stephenk@cc.gatech.edu>
Re: How do I split multi line strings in perl (Tad McClellan)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 07 Jul 2000 21:38:16 -0400
From: root <ZXCYE@SAMBAABMAS.GRO>
Subject: Hope this is the right group
Message-Id: <39668608.9DBC1E25@SAMBAABMAS.GRO>
i am using win32 perl AS ver perl 5.005 with IIS on WINNT Server I have
completed the development and testing. During the process some of the
web pages are forms and these forms are stored as text files. When ever
required
directories are created if they dont exist. All this was working until
my machine has broken down.
After rebuilting it completed and restoring my web site ( i do backups)
configured IIS to run Perl. all the forms work great, however
if directories are missing they are being created. If i create the
the directories every thing works just file.
Nothing as far i know, have done other then defaults. The IUSR_XXXXXPC
id is used by the web server. and has Execute permissions on the virtual
directory.
Any hints at what i missed.
thanks
------------------------------
Date: Sat, 08 Jul 2000 10:41:26 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Hope this is the right group
Message-Id: <396c044a.5337446@news.skynet.be>
root wrote:
>After rebuilting it completed and restoring my web site ( i do backups)
>configured IIS to run Perl. all the forms work great, however
>if directories are missing they are being created.>
^^^
I guess you meant "aren't".
> If i create the
>the directories every thing works just file.
You're trying to use mkdir()? What doe it say (in $!) if directory
creation fails? You're not trying to create a set of nested directories
in one go, are you? For example:
mkdir "c:/data/something/new", 0777;
will fail if the directory "c:/data/something" doesn't exist yet.
And, I don't know if this applies to your Windows server, but... is your
process allowed to create new directories in that location?
--
Bart.
------------------------------
Date: Sat, 08 Jul 2000 10:06:46 -0400
From: root <ZXCYE@SAMBAABMAS.GRO>
Subject: Re: Hope this is the right group
Message-Id: <39673576.973BF948@SAMBAABMAS.GRO>
i use the following command
if (system ("mkdir ./$VAR")) {
print "$VAR Created";}
else { print "$! ---$VAR Failed Creation";}
There is no error Message for $!, and it aways is true
the system call returns true and gives the name of the directory
it has created.
sorry about the typos before.
Bart Lateur wrote:
>
> root wrote:
>
> >After rebuilting it completed and restoring my web site ( i do backups)
> >configured IIS to run Perl. all the forms work great, however
> >if directories are missing they are being created.>
> ^^^
> I guess you meant "aren't".
>
> > If i create the
> >the directories every thing works just file.
>
> You're trying to use mkdir()? What doe it say (in $!) if directory
> creation fails? You're not trying to create a set of nested directories
> in one go, are you? For example:
>
> mkdir "c:/data/something/new", 0777;
>
> will fail if the directory "c:/data/something" doesn't exist yet.
>
> And, I don't know if this applies to your Windows server, but... is your
> process allowed to create new directories in that location?
>
> --
> Bart.
------------------------------
Date: Sat, 8 Jul 2000 10:21:14 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hope this is the right group
Message-Id: <slrn8mee6q.op0.tadmc@magna.metronet.com>
On Sat, 08 Jul 2000 10:06:46 -0400, ZXCYE@SAMBAABMAS.GRO <ZXCYE@SAMBAABMAS.GRO> wrote:
>i use the following command
>if (system ("mkdir ./$VAR")) {
> print "$VAR Created";}
>else { print "$! ---$VAR Failed Creation";}
>
>There is no error Message for $!,
There most likely IS something in $!, but it is only interesting
when system() has _failed_, and you only examine it when
the system() has succeeded!
>and it aways is true
>the system call returns true and gives the name of the directory
^^^^^^^^^^^^^^^^^^^^^^^^
system() returns true on *failure*.
It returns false on success (following the Unix conventions, which is
opposite of Perl's convention).
!system ("mkdir ./$VAR") || die "could not mkdir './$VAR' $!";
^
^ invert the sense of the return value
or
system ("mkdir ./$VAR") && die "could not mkdir './$VAR' $!";
^^
^^ invert the sense of the logic
or
unless (system ("mkdir ./$VAR")) {
^^^^^^
^^^^^^ invert the sense of the conditional
print "$VAR Created";
}
else {
print "$! ---$VAR Failed Creation";
}
>it has created.
At YAPC 19100 Larry Wall said that if he could go back in time
and change one thing about Perl, he said he would make system()
return false on failure.
( Which rather surprised me. I would have thought choosing a
different name for local() would be high on the list.
When
local $foo;
creates a *global* variable, something is tooooo weird.
)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 08 Jul 2000 14:12:47 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Hope this is the right group
Message-Id: <slrn8mesqc.rbj.abigail@alexandra.delanet.com>
Tad McClellan (tadmc@metronet.com) wrote on MMDIII September MCMXCIII in
<URL:news:slrn8mee6q.op0.tadmc@magna.metronet.com>:
""
"" At YAPC 19100 Larry Wall said that if he could go back in time
"" and change one thing about Perl, he said he would make system()
"" return false on failure.
He also said at YAPC 19100 (but for a different audience) that if he
could change one thing about Perl, it was to have localtime() return a
4 digit year.
"" ( Which rather surprised me. I would have thought choosing a
"" different name for local() would be high on the list.
""
"" When
""
"" local $foo;
""
"" creates a *global* variable, something is tooooo weird.
"" )
Ah, but it doesn't create a variable. It creates a *value*. A localized
value....
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Mon, 10 Jul 2000 08:38:40 GMT
From: Abel Almazan <abel@inlander.es>
Subject: How can i know when a string == NULL
Message-Id: <39698B9A.5AA443CD@inlander.es>
I want to know when a given string is == null
how can i do it in perl???
Thanx.
------------------------------
Date: Mon, 10 Jul 2000 10:04:29 +0100
From: "mike solomon" <mike.solomon@eps.ltd.uk>
Subject: Re: How can i know when a string == NULL
Message-Id: <8kc3kb$26fn9$1@ID-36965.news.cis.dfn.de>
I always use
if ( $foo eq "" )
I don't know if there is a better way of doing it but it works
Regards
Mike Solomon
Abel Almazan <abel@inlander.es> wrote in message
news:39698B9A.5AA443CD@inlander.es...
> I want to know when a given string is == null
>
> how can i do it in perl???
>
> Thanx.
>
------------------------------
Date: Mon, 10 Jul 2000 11:31:31 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: How can i know when a string == NULL
Message-Id: <396bb370.15654229@news.skynet.be>
Abel Almazan wrote:
>I want to know when a given string is == null
Doesn't work. In Perl, strings (er, "scalars") are either undefined, or
defined with a length which could be zero. So, depending on your program
requirements:
unless(defined $string) { ... }
or
unless(length $string) { ... }
If you're not sure if a scalar is defined, and you want to avoid
warnings, do both tests:
unless(defined $string && length $string) { ... }
The second test, length(), isn't done if the first test, defined(),
returns false.
--
Bart.
------------------------------
Date: Sat, 8 Jul 2000 14:57:37 +0900
From: "Dan and Shelly" <wedeking@msa.attmil.ne.jp>
Subject: how can I merge data from two text files into an excell spreadsheet file?
Message-Id: <8k6fl1$bpo$1@newsflood.tokyo.att.ne.jp>
Can anyone help me figure out how to merge data from two plain text files
into a
tab-delimeted text file that I can import into Microsoft Excell?
In one plain text file I have names and addresses of different people. In
the other plain text file I have names and phone numbers of some of the same
people.
I can use a perl script to select the names and addresses and insert tabs
between
the names and the addresses.
The part I'm having trouble figuring out is how to insert the phone numbers
from the second text file by matching up the names so that the name, phone
number, and address are all included in the file I will import into
Microsoft Excell.
while (FILE=names_and_addresses.txt) {
$name = substr(0,4);
$address = substr(6);
while(FILE2=names_and_phone_numbers.txt) {
if ($name ~= substr(0,4)) {
$phone_number = substr(8,8);
else {
$phone_number = "unknown";
}
print $name\t$phone_number\t$address > excell_import_file.txt;
}
Would the above work? I want to figure out how to make the script look
through the
entire names_and_phone_numbers.txt file for each name in the
names_and_addresses.txt file since the two files don't match up the same
names line-for-line. Excell uses tabs to delimit text so when I print out
the excell.txt file I insert tabs to separate the variables.
Dan
------------------------------
Date: Sat, 08 Jul 2000 11:30:35 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: how can I merge data from two text files into an excell spreadsheet file?
Message-Id: <39680e4b.1168639@news.skynet.be>
Dan and Shelly wrote:
>Can anyone help me figure out how to merge data from two plain text files
>into a tab-delimeted text file that I can import into Microsoft Excell?
Sure.
>In one plain text file I have names and addresses of different people. In
>the other plain text file I have names and phone numbers of some of the same
>people.
>The part I'm having trouble figuring out is how to insert the phone numbers
>from the second text file by matching up the names so that the name, phone
>number, and address are all included in the file I will import into
>Microsoft Excell.
>while (FILE=names_and_addresses.txt) {
Won't do.
>$name = substr(0,4);
>$address = substr(6);
Er... is your name always 4 characters long? Now *that* is a very short
name. And is the fifth character bogus, and the address the remainder of
the string? BTW you've still got a newline at the end of the address.
> while(FILE2=names_and_phone_numbers.txt) {
Again, won't work.
> if ($name ~= substr(0,4)) {
> $phone_number = substr(8,8);
> else {
> $phone_number = "unknown";
> }
Bad approach.
>print $name\t$phone_number\t$address > excell_import_file.txt;
>}
Absolutely nonperlish.
Best approach, IMO: use a hash with records, key = name.
I don't know how you're original files are orginized, but assuming that
the names are indeed 4 characters long (space padded, perhaps?), I also
assume that they are unique. Hmmm... how unlikely. Er... doe you care
about the ordering of records? I'll sort them by name.
open IN, "names_and_addresses.txt"
or die "Can't open addresses file: $!";
while(<IN>) {
chomp;
my($name, $address) = unpack "A4xA*", $_;
# replace by: my($name, $address) = split /\t/
# if source file happens to be tab delimited
$record{$name} = { name => $name, address => $address,
phone => 'unknown');
}
open IN, "names_and_phone_numbers.txt"
or die "Can't open phone numbers file: $!";
while(<IN>) {
chomp;
my($name, $phone) = unpack "A4XA*", $_;
$record{$name}{phone} = $phone if $record{$name};
}
# Data read. Now print it out.
open OUT, ">excell_import_file.txt"
or die "Can't write to Excell export file: $!";
{
local($\, $,) = ("\n", "\t");
foreach my $name (sort keys %record) {
print OUT @{$record{$name}}{qw(name phone address)};
}
}
--
Bart.
------------------------------
Date: Sat, 8 Jul 2000 02:08:24 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how can I merge data from two text files into an excell spreadsheet file?
Message-Id: <slrn8mdhao.oa8.tadmc@magna.metronet.com>
On Sat, 8 Jul 2000 14:57:37 +0900, Dan and Shelly <wedeking@msa.attmil.ne.jp> wrote:
>Can anyone help me figure out how to merge data from two plain text files
>into a
>tab-delimeted text file that I can import into Microsoft Excell?
OK, but please fix your word-wrap.
Usenet convention is 70-72 characters,
and
without alternating long/short
lines.
>The part I'm having trouble figuring out is how to insert the phone numbers
>from the second text file by matching up the names so that the name, phone
>number, and address are all included in the file I will import into
>Microsoft Excell.
Put the address info into a hash.
Key is name, value is address.
Use exists() to see if a name from the phone file is
also in the hash.
perldoc perldata
>while (FILE=names_and_addresses.txt) {
That is not Perl code.
If you post pseudo-code, you should state that it is pseudo-code.
>$name = substr(0,4);
>$address = substr(6);
> if ($name ~= substr(0,4)) {
^^
^^ eh?
> $phone_number = substr(8,8);
Looks like you have used substr() four times ...
... and read about what it will do for you zero times.
I find that astounding!
*Do not use functions that you haven't read the docs for*
If you don't, you cannot know what to expect from the function.
You have done the programming equivalent of signing a contract
without ever reading it!
Do so at your own peril (and don't come crying to us when
unread clauses come back to give you trouble).
You do not even have a correct argument list for any of
your four substr() calls...
>print $name\t$phone_number\t$address > excell_import_file.txt;
That looks like some Perl/shell hybrid language or something.
Please stop, you're confusing me.
>}
>
>Would the above work?
Never in a hunert million years.
It won't even compile (a usual first step in getting to "working").
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 04 Jul 2000 14:19:56 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: How dat werk? Re: Delayed HTML Output in PERL
Message-Id: <slrn8m3sk9.dsm.tjla@thislove.dyndns.org>
I was shocked! How could Abigail <abigail@delanet.com>
say such a terrible thing:
>$_ = "\x3C\x3C\x45\x4F\x54"; s/<<EOT/<<EOT/e; print;
>Just another Perl Hacker
>EOT
Okay I know that "\x3C\x3C\x45\x4F\x54" is the same as "<<EOT". And
umm s/<<EOT/<<EOT/ takes the string $_ and replaces the first instance
of "<<EOT" with uhh "<<EOT"...and then.../e executes the right side as an
expression...somehow. I'm lost. help.
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
Remember, there's a big difference between kneeling down and bending over.
- Frank Zappa
------------------------------
Date: Tue, 04 Jul 2000 17:43:06 +0200
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: How dat werk? Re: Delayed HTML Output in PERL
Message-Id: <3962060A.E3E7F179@bigfoot.com>
Gwyn Judd wrote:
> Okay I know that "\x3C\x3C\x45\x4F\x54" is the same as "<<EOT". And
> umm s/<<EOT/<<EOT/ takes the string $_ and replaces the first instance
> of "<<EOT" with uhh "<<EOT"...and then.../e executes the right side as an
> expression...somehow. I'm lost. help.
The expression is evaluated before the replacement takes
place.
--
Thorbjørn Ravn Andersen "...plus...Tubular Bells!"
http://bigfoot.com/~thunderbear
------------------------------
Date: 05 Jul 2000 04:12:36 GMT
From: db7654321@aol.comspamsux (David Bell)
Subject: How do I get rid of unwanted newlines when I print an array?
Message-Id: <20000705001236.02065.00002536@ng-cg1.aol.com>
Hello, I've got a (probably) very simple question that I can't find the answer
to: How do I get rid of newlines when I print the contents of an array? The
array is formatted like this:
someword
anotherword
etc...
I'd like to have it print like this: someword, anotherword, etc... . I looked
through the perldoc faq (I used perldoc -q array), and couldn't find anything.
Thanks!
-------------------------
David Bell - Otherwise known as DB7654321
Remember to remove nospam, notrash or anything odd looking from my email
address. :)
------------------------------
Date: Wed, 05 Jul 2000 06:13:56 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <slrn8m5k8k.gk1.bernard.el-hagin@gdndev25.lido-tech>
On 05 Jul 2000 04:12:36 GMT, David Bell <db7654321@aol.comspamsux> wrote:
>Hello, I've got a (probably) very simple question that I can't find the answer
>to: How do I get rid of newlines when I print the contents of an array? The
>array is formatted like this:
>
>someword
>anotherword
>etc...
>
>I'd like to have it print like this: someword, anotherword, etc... . I looked
>through the perldoc faq (I used perldoc -q array), and couldn't find anything.
>Thanks!
Read up on the "$," special variable (perldoc perlvar).
#!/usr/bin/perl -w
use strict;
my @array = qw/I wanna go to funky town/;
$, = ", ";
print @array;
Bernard
--
${qq=\x22=}=qq=\053=;$_="BeJUST_ANOTHERnaPERL_HACKERd\n";${qq=\x2c=}=qq=\x72=;
print split /[AC-Z_]$"/;
------------------------------
Date: Wed, 05 Jul 2000 06:40:04 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <slrn8m5ma9.j2m.rgarciasuarez@rafael.kazibao.net>
David Bell wrote in comp.lang.perl.misc:
>Hello, I've got a (probably) very simple question that I can't find the answer
>to: How do I get rid of newlines when I print the contents of an array? The
>array is formatted like this:
>
>someword
>anotherword
>etc...
>I'd like to have it print like this: someword, anotherword, etc...
You probably mean that the array elements are "someword\n", "anotherword\n",
etc. ? (If the contents of the array is read from a file, this is very
probable.) In this case you can
print join ', ', map { chop $_ ; $_ } @array;
(but this is only one of the Ways To Do It).
see perldoc -f join
perldoc -f map
perldoc -f chop
--
Rafael Garcia-Suarez
------------------------------
Date: Wed, 05 Jul 2000 10:38:27 +0100
From: Ade Talabi <adetalabi@clara.co.uk>
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <39630213.1668A30A@clara.co.uk>
David Bell wrote:
>
> Hello, I've got a (probably) very simple question that I can't find the answer
> to: How do I get rid of newlines when I print the contents of an array? The
> array is formatted like this:
>
> someword
> anotherword
> etc...
>
> I'd like to have it print like this: someword, anotherword, etc... . I looked
> through the perldoc faq (I used perldoc -q array), and couldn't find anything.
> Thanks!
>
> -------------------------
> David Bell - Otherwise known as DB7654321
>
> Remember to remove nospam, notrash or anything odd looking from my email
> address. :)
chop()
--
We see, whatever we want to see, whether visible or not
- AT. June 2000.
------------------------------
Date: Wed, 05 Jul 2000 14:00:46 GMT
From: dharkael@my-deja.com
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <8jvf23$7v3$1@nnrp1.deja.com>
In article <20000705001236.02065.00002536@ng-cg1.aol.com>,
db7654321@aol.comspamsux (David Bell) wrote:
> Hello, I've got a (probably) very simple question that I can't find
the answer
> to: How do I get rid of newlines when I print the contents of an
array? The
> array is formatted like this:
>
> someword
> anotherword
> etc...
>
> I'd like to have it print like this: someword, anotherword,
etc... . I looked
> through the perldoc faq (I used perldoc -q array), and couldn't find
anything.
> Thanks!
>
> -------------------------
> David Bell - Otherwise known as DB7654321
>
> Remember to remove nospam, notrash or anything odd looking from my
email
> address. :)
foreach $word(@array){
chomp($word);
}
should remove the new lines from each word in array;
Dharkael
~You can't put it together unless you've torn it apart first~
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 5 Jul 2000 09:18:50 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <slrn8m6ddq.ghk.tadmc@magna.metronet.com>
On Wed, 05 Jul 2000 06:40:04 GMT, Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>David Bell wrote in comp.lang.perl.misc:
>>How do I get rid of newlines when I print the contents of an array?
> print join ', ', map { chop $_ ; $_ } @array;
^^^^
> perldoc -f chop
^^^^
What's going on here?
Has someone been preaching the (false) virtues of chop() lately?
Or have the 'm' keys around the world stopped working? :-)
Use chop() to remove the last character.
Use chomp() to remove "line" ending sequences.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 5 Jul 2000 09:15:18 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <slrn8m6d76.ghk.tadmc@magna.metronet.com>
On Wed, 05 Jul 2000 10:38:27 +0100, Ade Talabi <adetalabi@clara.co.uk> wrote:
>David Bell wrote:
>>
>> How do I get rid of newlines when I print the contents of an array?
[ snip quoted .sig
Please don't quote .sigs
]
>chop()
If you were doing this 5 years ago, that would have been a
good suggestion.
But as we are doing it in the modern age (Perl 5),
perldoc -f chomp
would be Oh So Much Better!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 05 Jul 2000 14:12:20 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <7a4s64acoq.fsf@merlin.hyperchip.com>
rgarciasuarez@free.fr (Rafael Garcia-Suarez) writes:
> David Bell wrote in comp.lang.perl.misc:
> >Hello, I've got a (probably) very simple question that I can't find
> the answer
> >to: How do I get rid of newlines when I print the contents of an
> array? The
> >array is formatted like this:
> >
> >someword
> >anotherword
> >etc...
> >I'd like to have it print like this: someword, anotherword, etc...
>
> You probably mean that the array elements are "someword\n", "anotherword\n",
> etc. ? (If the contents of the array is read from a file, this is very
> probable.) In this case you can
> print join ', ', map { chop $_ ; $_ } @array;
A lot of people seem to forget that chomp() is generally better than
chop() for removing end-of-record characters, and that chomp() operates
as expected on arrays:
chomp @array;
print join ', ' => @array;
--Ala
------------------------------
Date: Wed, 5 Jul 2000 10:59:52 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <slrn8m6jb8.h0p.tadmc@magna.metronet.com>
On Wed, 05 Jul 2000 14:00:46 GMT, dharkael@my-deja.com <dharkael@my-deja.com> wrote:
> foreach $word(@array){
> chomp($word);
> }
>
>should remove the new lines from each word in array;
Yes, but so should merely:
chomp @array;
:-)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 05 Jul 2000 16:13:02 GMT
From: db7654321@aol.comspamsux (David Bell)
Subject: Re: How do I get rid of unwanted newlines when I print an array?
Message-Id: <20000705121302.02065.00002632@ng-cg1.aol.com>
> chomp @array;
> print join ', ' => @array;
>
Ahhhh... It works, and it's understandable! Thanks everyone!
-------------------------
David Bell - Otherwise known as DB7654321
Remember to remove nospam, notrash or anything odd looking from my email
address. :)
------------------------------
Date: Mon, 03 Jul 2000 17:27:43 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: How do I split multi line strings in perl
Message-Id: <3961054F.3881CC45@cc.gatech.edu>
James Nelson wrote:
> I am having some problems splitting a multiline strings in perl which I am
> <stdin> from a file. Some of the splits need to contain strings that are
> several lines long and others are single words.
>
> I tried splitting on the delimenator I used in the text file ^ but it seems
> to want to end the split with each new line, throughing things way out of
> order.
>
> please advice, thanks in advance.
2 ways of doing this:
1) Set $/ to the delimeter. Details are in perlvar
2) join all the text into one string, then split on the delimeter. Details are
in perlfunc.
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Mon, 3 Jul 2000 18:26:00 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do I split multi line strings in perl
Message-Id: <slrn8m24no.d1j.tadmc@magna.metronet.com>
[ I changed the Newsgroups header to only clp.misc:
I dunno what a "superlang" is.
I do not post in the alt.* hierarchy.
]
On Mon, 3 Jul 2000 16:01:30 -0500, James Nelson <james@kcnet.com> wrote:
>I am having some problems splitting a multiline strings in perl which I am
><stdin> from a file. Some of the splits need to contain strings that are
>several lines long and others are single words.
>
>I tried splitting on the delimenator
^^^^^^^
Errr, ... _where_ is your attempt?
You should post the code if you want help fixing it!
We're (generally) not mind readers hereabouts.
>I used in the text file ^ but it seems
>to want to end the split with each new line, throughing things way out of
>order.
>
>please advice, thanks in advance.
Oh. I think I can invoke the PSI::ESP module and
fix code blindfolded!
Put a backslash infront of the caret in the split pattern.
Caret is meta in regexes, you must escape it if you want to
match a literal one.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3569
**************************************