[19236] in Perl-Users-Digest
Perl-Users Digest, Issue: 1431 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 3 00:06:21 2001
Date: Thu, 2 Aug 2001 21:05:15 -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: <996811514-v10-i1431@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 2 Aug 2001 Volume: 10 Number: 1431
Today's topics:
#### HELP NEEDED #### <beguigne@hotmail.com>
Re: Can a regex or a tr/ do this sort of successive sub (Perl Girl)
Re: Can a regex or a tr/ do this sort of successive sub (Martien Verbruggen)
Re: Can a regex or a tr/ do this sort of successive sub <mjcarman@home.com>
Re: Creating small image of web page <bart.lateur@skynet.be>
data collection and file management (katherine)
DBI->connect parameters being pulled from XML file usin <usenet@lophty.com>
Re: FAQ: How do I handle circular lists? <SEE_MY_SIG@nospam.demon.co.uk>
FAQ: How do I shuffle an array randomly? <faq@denver.pm.org>
foreign data manipulation operators <tweb@swbell.net>
Re: Having some trouble with map <bart.lateur@skynet.be>
Help pls - very new at perl <beguigne@hotmail.com>
Re: Help pls - very new at perl <krahnj@acm.org>
Re: How do I... <acacia@online.no>
How to extract non-character data from socket stream? (Mark Johnson)
Re: How to extract non-character data from socket strea (Mark Johnson)
How to parse words out of a string into an array? (Mark Johnson)
Re: How to parse words out of a string into an array? (Damian James)
Re: How to parse words out of a string into an array? <krahnj@acm.org>
Re: How to parse words out of a string into an array? <godzilla@stomp.stomp.tokyo>
Re: How to parse words out of a string into an array? (Mark Johnson)
Re: How to parse words out of a string into an array? <godzilla@stomp.stomp.tokyo>
Install Problem needing assistance <dont@spam.me>
Re: interesting way to learn Perl (Damian James)
IO::File object and setting $| autoflush (Xeno Campanoli)
Re: IO::File object and setting $| autoflush (Xeno Campanoli)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 03 Aug 2001 00:02:07 -0400
From: Carlos Beguigne <beguigne@hotmail.com>
Subject: #### HELP NEEDED ####
Message-Id: <2a8kmtgggvd8ddsphsjsmfi63tte8o8f3a@4ax.com>
#############################################################################
#
#
# BSS: Create a Database file
#
#
#
# Info:
#
#
#
&make_db;
sub make_db {
use strict;
my $day = (time);
my $file = "order.$day.dat";
print "$day \n";
print "$file \n\n";
open(file_1, "> $file") or die "$file: REASON -> $!";
close(file_1) or die "$file: REASON -> $!";
}
This works well when I run it locally from my PC but it bombs out on
my ISP web server with the following error:
500 internal server error
reason: Premature end of script headers
Any help will be really appreciated...
Regards,
Carlos
------------------------------
Date: 2 Aug 2001 15:09:31 -0700
From: perlgirl@hotmail.com (Perl Girl)
Subject: Re: Can a regex or a tr/ do this sort of successive substitution?
Message-Id: <5fde2162.0108021409.249be9ed@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9mine2.r58.tadmc@tadmc26.august.net>...
> Perl Girl <perlgirl@hotmail.com> wrote:
> >I need to make a char-by-char substitution of one string into another.
> >For example, I need to replace each '?' below with the next available
> >char from the second scalar. I wish to end up with:
> >
> >cat
> >man1
> >dog 2
> >mou3se
> >hen 4
> >
> >
> > #!/usr/bin/perl -wd
> > use strict;
> >
> > $_='cat
> > man?
> > dog ?
> > mou?se
> > hen ?';
> >
> > my $m='1234';
> >
> > s/\?/$m/geos;
>
>
> You should not throw options willy-nilly onto the pattern.
>
> s///o is useless. There is no variable in your pattern.
>
> s///s is useless. There is no dot in your pattern.
>
> my $i;
> s/\?/ substr($m, $i++, 1) /ge;
>
>
> > print;
Thanks guys very good inputs. I guess I need to read up on the /e
regex switch. I think it warranted about 1 sentance in Camel- if you
can recommend some good places to find examples and more narratives on
it and other switches I promise to do some extra reading there :)
I'm not sure what you mean by
> s///s is useless. There is no dot in your pattern.
I use that when I have multiple line buffers to force the regex to
look at it all as one line. Why do I need a '.'?
s/\?/ substr($m, $i++, 1) /ge;
was a VERY nice solution. My solution involved building a huge regex
with a loop. Its so ugly I won't even show it here! But this is very
nice. I wonder what other uses mister "e" switch has?
Thanks guys,
PG
------------------------------
Date: Fri, 03 Aug 2001 03:26:45 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Can a regex or a tr/ do this sort of successive substitution?
Message-Id: <slrn9mk6fl.1rf.mgjv@verbruggen.comdyn.com.au>
On 2 Aug 2001 15:09:31 -0700,
Perl Girl <perlgirl@hotmail.com> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9mine2.r58.tadmc@tadmc26.august.net>...
>> Perl Girl <perlgirl@hotmail.com> wrote:
>> >I need to make a char-by-char substitution of one string into another.
>> > s/\?/$m/geos;
>>
>> You should not throw options willy-nilly onto the pattern.
>> s///s is useless. There is no dot in your pattern.
>
> Thanks guys very good inputs. I guess I need to read up on the /e
> regex switch. I think it warranted about 1 sentance in Camel- if you
> can recommend some good places to find examples and more narratives on
> it and other switches I promise to do some extra reading there :)
The perlre documentation probably contains some interesting
information:
perldoc perlre
> I'm not sure what you mean by
>
> > s///s is useless. There is no dot in your pattern.
>
> I use that when I have multiple line buffers to force the regex to
> look at it all as one line. Why do I need a '.'?
From perlre:
s Treat string as single line. That is, change "." to
match any character whatsoever, even a newline, which
normally it would not match.
That is /s main character: It makes . match a newline. Since your
pattern doesn't contain a ., the /s does nothing.
> s/\?/ substr($m, $i++, 1) /ge;
>
> was a VERY nice solution. My solution involved building a huge regex
> with a loop. Its so ugly I won't even show it here! But this is very
> nice. I wonder what other uses mister "e" switch has?
If you aren't interested in the next character from a string, but just
an increasing number:
$i = 0;
s/\?/ $i++ /ge;
or, if you want it formatted:
$i = 0;
s/\?/ sprintf "%03d", $i++ /ge;
Basically, you can do anything in there.
#!/usr/local/bin/perl -w
use strict;
$_ = "some long string that has some words in it\n";
sub mysub { "-$_[0]::$_[1]-" }
my $regex1 = my $regex2 = qr/\b.+?\b/;
s/($regex1) ($regex2)/ mysub($1, $2) /ge;
print;
__END__
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where
Commercial Dynamics Pty. Ltd. | would you put it?
NSW, Australia |
------------------------------
Date: Fri, 03 Aug 2001 03:37:59 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: Can a regex or a tr/ do this sort of successive substitution?
Message-Id: <3B6A1C2F.3C4A70C2@home.com>
Perl Girl wrote:
>
> tadmc@augustmail.com (Tad McClellan) wrote in message
> news:<slrn9mine2.r58.tadmc@tadmc26.august.net>...
> >
> > s///s is useless. There is no dot in your pattern.
>
> I guess I need to read up on the /e regex switch. I think it
> warranted about 1 sentance in Camel- if you can recommend some
> good places to find examples and more narratives on it and other
> switches I promise to do some extra reading there :)
Some switches (like /s) apply to all regexes. /e only applies to s///.
At any rate, there's not much to be said about /e in the docs -- it
causes Perl to treat the replacement portion of a s/// as something to
be evaluated (an expression) instead of as something to be interpolated
(a double-qouted string). What you do with that power is up to you. :)
See the perlre manpage and the s/// entry on the perlop manpage.
> I'm not sure what you mean by
>
> > s///s is useless. There is no dot in your pattern.
>
> I use that when I have multiple line buffers to force the regex to
> look at it all as one line. Why do I need a '.'?
You don't need a dot. You don't have one, and that's why you don't need
/s. The only thing /s does is change how Perl interprets '.' inside the
regex. Normally, it means "any character except a newline." With the /s
option, it means "any character at all (including newline)."
-mjc
------------------------------
Date: Fri, 03 Aug 2001 00:53:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Creating small image of web page
Message-Id: <bftjmtg5j19n305rir2fr366as5p5icb15@4ax.com>
Randal L. Schwartz wrote:
>ImageMagick and therefore PerlMagick can take .html input and generate
>PNG output if you have all the right helper programs. Scaling is
>trivial. I was thinking of doing that for one of my columns soon.
Since you cannot exactly predict what a rendered HTML page will look
like (it depends on the browser, the installed fonts, user preferences,
the browser window size, ...) an exact thumbnail is an impossibility.
If you want one approach, try taking a screen dump of a browser
window...
--
Bart.
------------------------------
Date: 2 Aug 2001 16:55:44 -0700
From: kstar8864@hotmail.com (katherine)
Subject: data collection and file management
Message-Id: <848d6bd2.0108021555.29c98841@posting.google.com>
Hi!
I am trying to write a data collection program (in Perl) that will
gather system statistics synchronously using utilities like iostat,
vmstat, cpustat, netstat, etc.
My basic approach is to fork a process to manage each utility and
gather the data from the utility (using pipes) which is then stored
into a file. Therefore each utility is started and will output data
every second; this data is stored into a file. Then there is an
"agent" process that will go and take the last complete line of each
file (one for each utility) every 5 seconds and store it into one
global file (I use tail and head commands to do this). I am only
interested in maintaining the one big file to to minimize disk usage.
Any thoughts on how I could do this?
Any help/suggestions would be greatly appreciated.
Thanks!
Katherine Roth
kstar8864@hotmail.com
------------------------------
Date: Thu, 02 Aug 2001 21:33:53 -0400
From: brian donovan <usenet@lophty.com>
Subject: DBI->connect parameters being pulled from XML file using XML::DOM methods - throws error
Message-Id: <3B69FF81.1010700@lophty.com>
I'm experiencing a curious problem.
In a script that I'm working on, I connect to a database sith the line:
my $dbh = DBI->connect($datasrc,$dbuser,$dbpass, {RaiseError => 1});
The values of the params ($datasrc, $dbuser, and $dbpass) are being
taken from an XML file - the relevant fragment is :
<database>
<datasourcename>
DBI:mysql:my_db_name:localhost
</datasourcename>
<dbusername>
my_db_username
</dbusername>
<dbpass>
my_db_pass
</dbpass>
</database>
I'm processing the xml file with XML::DOM methods (getData) and dropping
the values of the text nodes into a hash (it makes sense for what I'm
doing, although from the fragment shown here, it will seem like overkill
to you). The hash values are what is passed to the subroutine
containing the line that makes the database connection.
When I was pulling the hash values from a plain text config file, all
was well. If I replace the hash elements in the sub call with the
quoted values from the XML file or paste them directly into the
DBI->conect(..), it works.
Right now, though, I'm getting an error :
Software error:
Can't connect(
DBI:mysql:my_db_name:localhost
my_db_username
my_db_pass
HASH(0x85efb68)), no database driver specified and DBI_DSN env var not
set at db-functions.pl line 16
Line 16 is the line in my script containing the DBI-connect.
Anybody have any clue what the problem could be?
Thanks,
brian donovan
------------------------------
Date: Thu, 2 Aug 2001 23:38:08 +0100
From: James Taylor <SEE_MY_SIG@nospam.demon.co.uk>
Subject: Re: FAQ: How do I handle circular lists?
Message-Id: <ant022208b49fNdQ@oakseed.demon.co.uk>
In article <RRga7.76$l_m.170718720@news.frii.net>,
PerlFAQ Server wrote:
>
> How do I handle circular lists?
>
> Circular lists could be handled in the traditional fashion with linked
> lists, or you could just do something like this with an array:
>
> unshift(@array, pop(@array)); # the last shall be first
> push(@array, shift(@array)); # and vice versa
Shouldn't this FAQ entry discuss garbage collection?
If the linked list approach is used it is not enough just to let go of
the structure because the reference counts will not be zero, and the
result will be a memory leak. It is necessary to break the cycle
before letting go. I think the FAQ should at least mention this.
--
James Taylor <james (at) oakseed demon co uk>
Based in Southam, Cheltenham, UK.
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Fri, 03 Aug 2001 00:20:39 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I shuffle an array randomly?
Message-Id: <r7ma7.87$l_m.171095552@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How do I shuffle an array randomly?
Use this:
# fisher_yates_shuffle( \@array ) :
# generate a random permutation of @array in place
sub fisher_yates_shuffle {
my $array = shift;
my $i;
for ($i = @$array; --$i; ) {
my $j = int rand ($i+1);
@$array[$i,$j] = @$array[$j,$i];
}
}
fisher_yates_shuffle( \@array ); # permutes @array in place
You've probably seen shuffling algorithms that work using splice,
randomly picking another element to swap the current element with
srand;
@new = ();
@old = 1 .. 10; # just a demo
while (@old) {
push(@new, splice(@old, rand @old, 1));
}
This is bad because splice is already O(N), and since you do it N times,
you just invented a quadratic algorithm; that is, O(N**2). This does not
scale, although Perl is so efficient that you probably won't notice this
until you have rather largish arrays.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
04.46
--
This space intentionally left blank
------------------------------
Date: Thu, 2 Aug 2001 20:37:15 -0500
From: "twebber" <tweb@swbell.net>
Subject: foreign data manipulation operators
Message-Id: <7lna7.77$%u4.5307@nnrp1.sbc.net>
I don't know perl, but have to fix a broken app.
I need to decipher what this code is doing. My vpi's range from 0-7 and
vci's range from 32-431. For example, with a vpi3/vci288, what would the
three Id variables contain?
$num = ($vpi << 9) | $vci;
$srcProbeId = ($num >> 8) & 0x001F;
$cosId = ($num >> 5) & 0x0007;
$dstProbeId = $num & 0x001F;
Thanks for any help.
Terry
------------------------------
Date: Fri, 03 Aug 2001 00:48:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Having some trouble with map
Message-Id: <h7tjmt44pl0kfo8gqu5qnfhtgpem3lhhe8@4ax.com>
John Kramer wrote:
>I was using map rather than for because there are 10 instances of this
>check running in a row and quite frankly I don't want to type out that
>many for loops.
???
A map() plus block in void context is equivalent to one for loop.
One.
I think you should have written:
foreach (@port) {
... # content of map block here
}
--
Bart.
------------------------------
Date: Thu, 02 Aug 2001 21:17:27 -0400
From: Carlos Beguigne <beguigne@hotmail.com>
Subject: Help pls - very new at perl
Message-Id: <5jujmtkho3adlc13hpojn86uihmvni9n78@4ax.com>
use strict;
my $day = (time);
my $file = "order.$day.dat";
print "$day \n";
print "$file ";
open(file_1, '>>"$file"') or die "$file: REASON -> $!";
print file_1 "0";
close(file_1) or die "$file: REASON -> $!";
the open statement generates the following error:
order.996801242.dat: REASON -> Invalid argument at example2.pl line
15.
If I remove the "" from $file then it creates a file called $file
Any help appreciated
------------------------------
Date: Fri, 03 Aug 2001 01:33:39 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help pls - very new at perl
Message-Id: <3B69FFAE.22AA3F0B@acm.org>
Carlos Beguigne wrote:
>
> use strict;
> my $day = (time);
> my $file = "order.$day.dat";
>
> print "$day \n";
> print "$file ";
>
> open(file_1, '>>"$file"') or die "$file: REASON -> $!";
You are trying to open a file named "$file" (double quote, dollar sign,
f, i, l, e, double quote) You should read up on Quote and Quote-like
Operators in the perlop man page. But anyway, the solution is to use
double quotes so that the variable will be interpolated.
open FILE_1, ">>$file" or die "$file: REASON -> $!";
> print file_1 "0";
> close(file_1) or die "$file: REASON -> $!";
>
> the open statement generates the following error:
> order.996801242.dat: REASON -> Invalid argument at example2.pl line
> 15.
> If I remove the "" from $file then it creates a file called $file
>
> Any help appreciated
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 3 Aug 2001 01:35:58 -0700
From: "Acacia" <acacia@online.no>
Subject: Re: How do I...
Message-Id: <ptla7.299$GS4.3149@news1.oke.nextra.no>
ok, it's like this. I run a news updating system and on the front page I
want only the first
200 characters of a news posting. However, when I include a link (<a
href="etc">) amongst
the first 200 characters, the actual lenght becomes less than 200 characters
(200 minus the link code).
$readchars = 200;
$shortsummary = substr($newstext,0,$readchars);
what I want is to change the $readchars according to the number of < and >
(and the content between)
found in $shortsummary.
Again, thank for your help.
...sorry about the e-mail reply, pressed the wrong button :)
----- Original Message -----
From: "Tad McClellan" <tadmc@augustmail.com>
Newsgroups: comp.lang.perl.misc
Sent: Thursday, August 02, 2001 9:28 AM
Subject: Re: How do I...
> Tarjei Mandt <acacia@online.no> wrote:
>
> >Subject: How do I...
>
>
> Please put the subject of your article in the Subject of your article.
>
>
> >I need to find the number of characters between a < and a > in a string.
> ><a href="#"> would return 10
>
>
> What have you tried already?
>
> If you show us your code, we can help you fix it.
>
> Here are a couple of dirty hacks that might maybe sometimes
> kinda sorta do what you seem to be asking for:
>
>
> if ( /<([^>]+)>/ ) { # using regexen is futile and fragile!
> print length($1), "\n";
> }
>
> # this is easy to break too
> if (my $open = index($_, '<') and my $close = index($_, '>') ) {
> die "huh?" if $close < $open;
> print $close - $open - 1, "\n";
> }
>
>
> >Also, how do i delete HTML tags like <img src="#"> or <br> from a string?
> >
> >Help would be much appreciated.
>
>
> Checking the Perl FAQ *before* posting to the Perl newsgroup would be
> much appreciated.
>
> perldoc -q HTML
>
> "How do I remove HTML from a string?"
>
>
> Which points out several cases of legal HTML that will break
> the code above.
>
> Use a module that understands HTML for processing HTML.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Fri, 03 Aug 2001 03:12:08 GMT
From: crvmp3@hotmail.com (Mark Johnson)
Subject: How to extract non-character data from socket stream?
Message-Id: <90F1E7232markjohnsononfiberco@24.28.95.190>
I am connecting to a network device (a router actually) over TCP. One of
the commands on the router outputs the results using ANSI screen formatting
codes (nice for humans, bad for automated system monitors).
If I simply output the results to a file they look like:
^[[0;5hsome text here^[[0;0h;^[[0;6hsome more text^[[0;0h
but I need to be able to parse them out within the script but I don't know
how to look for them since I can't use the ASCII representation in my
parser code since they are binary (as far as I understand).
Any suggestions on how to extact these codes?
sub ReadFromDevice()
{
my $response = <$SOCKET>;
my $text = PruneControlCodes( $response );
return $text;
}
sub PruneControlCodes( $response )
{
# ack! how to write?
}
I am so frustrated at this point! I'd be grateful for any help you can
offer.....
thanks!
------------------------------
Date: Fri, 03 Aug 2001 03:18:24 GMT
From: crvmp3@hotmail.com (Mark Johnson)
Subject: Re: How to extract non-character data from socket stream?
Message-Id: <90F1E5F0Fmarkjohnsononfiberco@24.28.95.190>
crvmp3@hotmail.com (Mark Johnson) wrote in
<90F1E7232markjohnsononfiberco@24.28.95.190>:
>I am connecting to a network device (a router actually) over TCP. One
>of the commands on the router outputs the results using ANSI screen
>formatting codes (nice for humans, bad for automated system monitors).
>
>If I simply output the results to a file they look like:
>
> ^[[0;5hsome text here^[[0;0h;^[[0;6hsome more text^[[0;0h
>
Possibly I should have mentioned that these ANSI sequences start with a
decimal 27 (the ESC character) and end with an 'h'. So I guess my problem
initially is how to find the decimal 27 in the character string....
------------------------------
Date: Fri, 03 Aug 2001 00:08:14 GMT
From: crvmp3@hotmail.com (Mark Johnson)
Subject: How to parse words out of a string into an array?
Message-Id: <90F1CF0E9markjohnsononfiberco@24.28.95.150>
I need to take a string and parse all the "words" into an array which i can
then iterate through.
I tried:
my $str = "mary had a little lamb";
my @arr = $str ~= /w+/w+/g;
my $rv = @arr;
print( "there are $rv words in $str" );
but that didn't seem to work...
thanks for your time!
------------------------------
Date: 3 Aug 2001 01:02:38 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: How to parse words out of a string into an array?
Message-Id: <slrn9mju0d.bvo.damian@puma.qimr.edu.au>
Mark Johnson chose Fri, 03 Aug 2001 00:08:14 GMT to say this:
>I need to take a string and parse all the "words" into an array which i can
>then iterate through.
>
>I tried:
>
> my $str = "mary had a little lamb";
> my @arr = $str ~= /w+/w+/g;
> my $rv = @arr;
> print( "there are $rv words in $str" );
>
>but that didn't seem to work...
>...
See perldoc -f split.
$_ = 'mary had a little lamb';
my @arr = split;
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: Fri, 03 Aug 2001 01:02:22 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to parse words out of a string into an array?
Message-Id: <3B69F8B8.D5C7F7D5@acm.org>
Mark Johnson wrote:
>
> I need to take a string and parse all the "words" into an array which i can
> then iterate through.
Missed it by || that much. :-)
> I tried:
>
> my $str = "mary had a little lamb";
> my @arr = $str ~= /w+/w+/g;
my @arr = $str ~= /(\w+)/g;
> my $rv = @arr;
> print( "there are $rv words in $str" );
>
> but that didn't seem to work...
>
> thanks for your time!
You're welcome!
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 02 Aug 2001 18:32:43 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How to parse words out of a string into an array?
Message-Id: <3B69FF3B.487E43E1@stomp.stomp.tokyo>
Mark Johnson wrote:
> I need to take a string and parse all the
> "words" into an array which i can
> then iterate through.
> I tried:
(snipped)
Appears, like so many others, you are having
difficulties deciding if you should uppercase
your personal pronoun "I" or not. It is of
interest to me to read so many different
people exhibiting this precise idiom.
Others have exemplified how to create an array.
Per your code, you are counting words. Use of
transliteration is quicker and more efficient
for this task.
A presumption is made there are no leading spaces,
no trailing spaces and no multiple spaces. If this
is a problem, simply remove leading and trailing
spaces then reduce multiple spaces to single spaces.
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
$string = "mary had a little lamb";
$count = $string =~ tr/ // + 1;
print "String: $string\n\n";
print "There are $count words in your string.";
exit;
PRINTED RESULTS:
________________
String: mary had a little lamb
There are 5 words in your string.
------------------------------
Date: Fri, 03 Aug 2001 02:36:27 GMT
From: crvmp3@hotmail.com (Mark Johnson)
Subject: Re: How to parse words out of a string into an array?
Message-Id: <90F1DF9FEmarkjohnsononfiberco@24.28.95.190>
Thanks for your reply! See below on the pronoun bit.
godzilla@stomp.stomp.tokyo (Godzilla!) wrote in <3B69FF3B.487E43E1
@stomp.stomp.tokyo>:
>Mark Johnson wrote:
>
>> I need to take a string and parse all the
>> "words" into an array which i can
>> then iterate through.
>
>> I tried:
>
>(snipped)
>
>Appears, like so many others, you are having
>difficulties deciding if you should uppercase
>your personal pronoun "I" or not. It is of
>interest to me to read so many different
>people exhibiting this precise idiom.
>
>
I guess the reasons why folks use the lower case pronoun are possibly due
to:
1) a life-time spent infront of a unix terminal
2) writing way too much C, C++, Perl, and Java for one's own good
3) simple typos & other carelessness
4) the informal context of usenet
5) all of the above
6) metaphorical modesty :)
cheers!
mark
------------------------------
Date: Thu, 02 Aug 2001 20:07:40 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How to parse words out of a string into an array?
Message-Id: <3B6A157C.18DBD6EC@stomp.stomp.tokyo>
Mark Johnson wrote:
> Thanks for your reply! See below on the pronoun bit.
> Godzilla!
> >Mark Johnson wrote:
(snipped)
> >Appears, like so many others, you are having
> >difficulties deciding if you should uppercase
> >your personal pronoun "I" or not. It is of
> >interest to me to read so many different
> >people exhibiting this precise idiom.
> I guess the reasons why folks use the lower case pronoun
> are possibly due to:
> 1) a life-time spent infront of a unix terminal
> 2) writing way too much C, C++, Perl, and Java for one's own good
> 3) simple typos & other carelessness
> 4) the informal context of usenet
> 5) all of the above
> 6) metaphorical modesty :)
No guessing on this. These reasons English teachers almost
always chastise others for spelling, grammar, structure,
tense, style, rhythm hmm... well, there are ten reasons.
1. Anal Retentive
2. Pedantic
3. Anal Retentive
4. Pedantic
5. Anal Retentive
6. Pedantic
7. Anal Retentive
8. Pedantic
9. Anal Retentive
10. Pedantic
You will notice in my articles, my right margins are almost
as precise as my left margins or, at least pretty in nature.
Work on this.
Godzilla! Queen Of Existentialist Metaphors.
------------------------------
Date: Fri, 03 Aug 2001 03:11:55 GMT
From: Jon Santarelli <dont@spam.me>
Subject: Install Problem needing assistance
Message-Id: <%Doa7.414$xY6.32958@newsread2.prod.itd.earthlink.net>
Hi All,
Recently I have asked our sys admins to install a newer version of Perl
on our unix boxes so that I could use some of the new features. We
were at ver. 4 and ver. 5.6.1 was just installed and I think that the
install went south some how. Before I go to the admins and say 'You
blew it, now fix it!' I would like a confirmation if the install was
blown, hopefully even a remedy to present. I do hope some kind person
could help.
The below script produced the error below. I have not used the Socket
module before - but would like to :). Just a very simple program
really.
What I did notice is that in the @INC directories do not really
correspond to the directory structure that is on the box
(/opt/perl5/lib/5.6.1/PA-RISC1.1/auto/Socket/Socket.sl). The 'auto'
directory is absent from @INC.
What I have noticed is that Socket.pm is being looked for and all the
directories only have files ending in .sl in them. Even trying to do a
simple perldoc gives an error that it cannot find warnings.pm (or
something similar).
Thanks
Jon
--------------------------------------------
Current Setup: ==>$ uname -mrs = HP-UX B.11.00 9000/800
The version of perl installed is 5.6.1. Ver 4 is still installed, but
in a different directory.
--------------------------------------------
== Here is the script ==
#!/opt/perl5/bin/perl
use Socket;
#$site_name = 'www.cpan.org';
#$address = inet_ntoa(inet_aton($site_name));
#print "The DNS entry of $site_name is address\n";
--------------------------------------------
== Here are the errors from executing the script ==
==>$ cpan.pl
Can't locate Socket.pm in @INC (@INC contains:
/opt/perl5/lib/5.6.1/PA-RISC1.1
/opt/perl5/lib/5.6.1
/opt/perl5/lib/site_perl/5.6.1/PA-RISC1.1
/opt/perl5/lib/site_perl/5.6.1
/opt/perl5/lib/site_perl .) at cpan.pl line 3.
BEGIN failed--compilation aborted at cpan.pl line 3.
--------------------------------------------
------------------------------
Date: 2 Aug 2001 22:07:25 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: interesting way to learn Perl
Message-Id: <slrn9mjjnu.44f.damian@puma.qimr.edu.au>
Tad McClellan chose Thu, 2 Aug 2001 11:28:31 -0400 to say this:
>...
>What was the advantage to your approach again?
>
Presumably that people taking it will pay money to the OP's organisation,
which (guessing from the text of the post) appears to offer some service
based on user-mode linux. A very thinly disguised advertisement, yes?
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: 3 Aug 2001 03:00:35 GMT
From: xeno@eskimo.com (Xeno Campanoli)
Subject: IO::File object and setting $| autoflush
Message-Id: <9kd44j$966$1@eskinews.eskimo.com>
I want to make my output on my IO::File object $ioo be immediately
flushed when a print $ioo "something";. I can't seem to set this
with either $| = 1, or select($ioo,$|=1); Can someone please tell
me how to do this? Sorry if it should be obvious.
Xeno
------------------------------
Date: 3 Aug 2001 03:12:10 GMT
From: xeno@eskimo.com (Xeno Campanoli)
Subject: Re: IO::File object and setting $| autoflush
Message-Id: <9kd4qa$9d7$1@eskinews.eskimo.com>
Xeno Campanoli (xeno@eskimo.com) wrote:
: I want to make my output on my IO::File object $ioo be immediately
: flushed when a print $ioo "something";. I can't seem to set this
: with either $| = 1, or select($ioo,$|=1); Can someone please tell
: me how to do this? Sorry if it should be obvious.
Never mind. I figured it out. I must have been suffering typoitis before.
$ioo->autoflush($bool);
: Xeno
------------------------------
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 1431
***************************************