[22327] in Perl-Users-Digest
Perl-Users Digest, Issue: 4548 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 11 06:05:45 2003
Date: Tue, 11 Feb 2003 03:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 11 Feb 2003 Volume: 10 Number: 4548
Today's topics:
[Regex] Removing lines not containing a substring (Allan Cady)
Re: [Regex] Removing lines not containing a substring (Jay Tilton)
Re: [Regex] Removing lines not containing a substring (Anno Siegel)
Re: ActivePerl, upgraded then downgraded, problems! (Philip Lees)
Re: Bad Output from Perldoc <rbclary@cox-internet.com>
Re: best Perl book for a newbi <xyf@nixnotes.org>
building hash <jvandervloet@hotmail.com>
building hash <jvandervloet@hotmail.com>
Re: building hash <tassilo.parseval@post.rwth-aachen.de>
Re: building hash (Anno Siegel)
Re: building hash <jvandervloet@hotmail.com>
call subroutines from a different file <dbird@no-spam.sghms.ac.uk>
Re: call subroutines from a different file (Anno Siegel)
Re: Controlling order of precedence <bart.lateur@pandora.be>
Re: Data access with perl <simon.oliver@nospam.umist.ac.uk>
Re: decompress a tar.Z fine in perl <bigj@kamelfreund.de>
Re: decompress a tar.Z fine in perl <abigail@abigail.nl>
Re: How to Iterate through a String <lockner@cse.psu.edu>
Re: How to Iterate through a String <peakpeek@purethought.com>
Re: How to Iterate through a String <goldbb2@earthlink.net>
Re: How to Iterate through a String <wyzelli@yahoo.com>
Re: Quick regexp question <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Quick regexp question <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Request help with this script (Jay Tilton)
strict and warnings <noreply@gunnar.cc>
Re: strict and warnings <tassilo.parseval@post.rwth-aachen.de>
threaded File::Glob, static GLOB_ERROR semantics (Michael Pomraning)
Variation on iterating through a string <lockner@cse.psu.edu>
Re: Variation on iterating through a string <goldbb2@earthlink.net>
Re: Variation on iterating through a string <jurgenex@hotmail.com>
Re: Why won't my for loop work? (Karen Lofstrom)
Re: Why won't my for loop work? (Helgi Briem)
Re: Why won't my for loop work? (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Feb 2003 23:34:12 -0800
From: allancady@yahoo.com (Allan Cady)
Subject: [Regex] Removing lines not containing a substring
Message-Id: <d563b154.0302102334.969afcf@posting.google.com>
The script below removes all lines from the source data that don't
begin (after whitespace) with '<td'. It takes four substitutions to
accomplish this. I'm wondering if there's a way to do this in one
substitution?
More generally, can you match lines that _don't_ contain a specified
substring? Or even more general, can you match any string based on
"anything but this substring"? What I do below depends on the '<td'
being the first non-whitespace in the line... what if I were looking
for a substring that could be at any position in the line?
Thanks... here's my script:
# Load data
read(DATA, $data, 65536);
# Left-justify all lines
$matchcount = $data =~ s{^\s*}{}mgi;
# Get rid of all lines that don't start with '<td'
$matchcount = $data =~ s{^[^<].*\n}{}mgi;
$matchcount = $data =~ s{^.[^t].*\n}{}mgi;
$matchcount = $data =~ s{^..[^d].*\n}{}mgi;
print "\nResult:\n";
print $data;
__DATA__
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</table>
------------------------------
Date: Tue, 11 Feb 2003 08:13:07 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: [Regex] Removing lines not containing a substring
Message-Id: <3e48ae63.146119143@news.erols.com>
allancady@yahoo.com (Allan Cady) wrote:
: The script below removes all lines from the source data that don't
: begin (after whitespace) with '<td'. It takes four substitutions to
: accomplish this. I'm wondering if there's a way to do this in one
: substitution?
Does it have to use s/// ?
: More generally, can you match lines that _don't_ contain a specified
: substring? Or even more general, can you match any string based on
: "anything but this substring"? What I do below depends on the '<td'
: being the first non-whitespace in the line... what if I were looking
: for a substring that could be at any position in the line?
It feels like the logic is inverted, making an easy problem into a
difficult one.
Instead of "throw away what does not match," change it to "keep what
does match."
index() is a better tool than m// for finding simple substrings.
my $data = <<EODATA;
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</table>
EODATA
$data = join "\n", grep index($_, '<td') > -1, split("\n", $data);
print $data;
------------------------------
Date: 11 Feb 2003 08:24:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [Regex] Removing lines not containing a substring
Message-Id: <b2abva$h8l$1@mamenchi.zrz.TU-Berlin.DE>
Allan Cady <allancady@yahoo.com> wrote in comp.lang.perl.misc:
> The script below removes all lines from the source data that don't
> begin (after whitespace) with '<td'. It takes four substitutions to
> accomplish this. I'm wondering if there's a way to do this in one
> substitution?
>
> More generally, can you match lines that _don't_ contain a specified
> substring?
That's the !~ operator. It is simply a negated match.
> Or even more general, can you match any string based on
> "anything but this substring"? What I do below depends on the '<td'
> being the first non-whitespace in the line... what if I were looking
> for a substring that could be at any position in the line?
>
> Thanks... here's my script:
You should use warnings and strict.
> # Load data
> read(DATA, $data, 65536);
Reading all the file in one go is rarely necessary. In this case
it makes things harder for you.
> # Left-justify all lines
> $matchcount = $data =~ s{^\s*}{}mgi;
What is $matchcount for? You never use it.
> # Get rid of all lines that don't start with '<td'
> $matchcount = $data =~ s{^[^<].*\n}{}mgi;
> $matchcount = $data =~ s{^.[^t].*\n}{}mgi;
> $matchcount = $data =~ s{^..[^d].*\n}{}mgi;
Everything else aside, these substitutions result in a lot of
string copying.
> print "\nResult:\n";
> print $data;
>
> __DATA__
> <table>
> <tr>
> <td>One</td>
> <td>Two</td>
> <td>Three</td>
> </tr>
> </table>
Just work on the file line by line.
my @data;
while ( <DATA> ) {
next unless s/\s*<td/<td/;
push @data, $_;
}
print @data;
Anno
------------------------------
Date: Tue, 11 Feb 2003 07:38:14 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: ActivePerl, upgraded then downgraded, problems!
Message-Id: <3e48a71a.63021140@news.grnet.gr>
On 10 Feb 2003 15:24:50 GMT, randy@theoryx5.uwinnipeg.ca (Randy Kobes)
wrote:
>On Mon, 10 Feb 2003 07:49:37 GMT,
> Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>>On Fri, 07 Feb 2003 19:00:37 GMT, Robert Young <rob@webteacher.com>
>>wrote:
>>
>>>I upgraded to 5.8, then downgraded to 5.6.1, and now when I run in ppm:
>>>install DBD-mysql
>>>I get a message that the module was found but is is not built for my
>>>version of Perl.
>>> Error installing package 'DBD-mysql': Read a PPD for 'DBD-mysql',
>>>but it is not intended for this build of Perl (MSWin32-x86-multi-thread)
>>
>>I've been getting exactly this problem recently trying to install
>>CGI::Session or Apache::Session with ppm.
>>
>>I'm using perl 5.6.1 on Windows 2000 and I haven't upgraded or
>>downgraded at all.
>>
>>Does anybody know what's going on?
>
>The message about "not intended for this build ..." means
>that ppm found a ppd file whose name matched what you were
>after, but the ARCHITECTURE tag in the ppd file didn't
>correspond to your system.
Checking again I see that Apache::Session mentions only Linux, but the
CGI::Session page gives the following spec:
PPM Platforms: Linux Solaris Windows
Version: CGI-Session 0.01
Perl Version: 5.6
http://aspn.activestate.com/ASPN/Modules/dist_html?dist_id=11032
Or am I misunderstanding what the ARCHITECTURE tag represents?
I've never had a problem with ppm before this.
Phil
--
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Mon, 10 Feb 2003 23:18:19 -0600
From: "Rick Clary" <rbclary@cox-internet.com>
Subject: Re: Bad Output from Perldoc
Message-Id: <v4h1t43keah2a7@corp.supernews.com>
"James E Keenan" <jkeen@concentric.net> wrote in message
news:b17b0n$l8i@dispatch.concentric.net...
> I have just installed Perl 5.8.0, ActivePerl build 804, on a machine
running
> Windows95 and I am experiencing problems with the 'perldoc' command
running
> from the command prompt. Under each of the following three, very common
> situations:
>
> perldoc -f [builtinfunction]
> perldoc -q [word relating to FAQ]
> perldoc [ModuleName]
>
I had the same experience when I went from 5.6.1 to 5.8.0 on two Win98
boxes. In each case, I removed 5.6.1 before installing 5.8.0.
Rather than adding white space, it appears to me that the lines are
terminated with a linefeed, but no carriage return so the more pager is
dropping straight down without going back to the left of the window.
I haven't tracked it down yet, but there are still some avenues I haven't
explored. I'll post a solution if I find one.
--Rick
------------------------------
Date: Tue, 11 Feb 2003 05:48:25 GMT
From: ktb <xyf@nixnotes.org>
Subject: Re: best Perl book for a newbi
Message-Id: <slrnb4h3l6.djq.xyf@scab.nixnotes.org>
In article <65050d4c.0302102010.5225f1e8@posting.google.com>, samphdauto wrote:
> Hello
> I come from a vb backgound and want to learn Perl.. what is the latest
> book you recommned me to start with. the version of perl I have is
> 5.8.0 which is the latest 'I think'.
Running the command -
perldoc -q book
Will net you a URL -
http://www.perl.com/perl/critiques/index.html
This site has a book list as well -
http://learn.perl.org/
hth,
kent
--
To know the truth is to distort the Universe.
Alfred N. Whitehead (adaptation)
------------------------------
Date: Tue, 11 Feb 2003 09:02:32 GMT
From: "joeri" <jvandervloet@hotmail.com>
Subject: building hash
Message-Id: <I_22a.43628$Jd.5444@afrodite.telenet-ops.be>
Hi,
I have a 75 MB file consisting of lines that look like:
S0973708 Other operation on meninges OS
S0873517 Excision of lesion of brain meninges
S0873177 Excision brain meninges lesion
S1295875 Removal of lesion of brain meninge
The first element on each line is some sort of ID, followed by a tab,
followed by some string.
I want to load these into a hash like so, assuming that IN is the filehandle
associated with the above file:
while(<IN>) {
$string{$1}={$2} if $_ =~ /(.*)\t(.*)\n/;
}
This goes pretty fast at the start, but really slows down as the hash grows
bigger. This
is probably due to the fact that while assigning a value to a key, Perl
checks to see if the key already
exists. The question here is, if I'm sure that the keys I will be using for
the hash are unique, so that there
is no need to check if the key already exists, can I build a hash or
something similar for quick
lookup later more rapidly?
Thanks,
J
------------------------------
Date: Tue, 11 Feb 2003 09:02:32 GMT
From: "joeri" <jvandervloet@hotmail.com>
Subject: building hash
Message-Id: <I_22a.43629$Jd.5489@afrodite.telenet-ops.be>
Hi,
I have a 75 MB file that looks like:
S0973708 Other operation on meninges OS
S0873517 Excision of lesion of brain meninges
S0873177 Excision brain meninges lesion
S1295875 Removal of lesion of brain meninge
I want to load these into a hash, but I don't want Perl to check all the
keys
in the hash every time it adds a new key, value pair to it, because I know
that
the first element on each line, which I use as a key is unique. Is this
possible?
Currently I do it like so, assuming that IN is the filehandle associated
with the above file:
while(<IN>) {
$string{$1}={$2} if $_ =~ /(.*)\t(.*)\n/;
}
Thanks,
J
------------------------------
Date: 11 Feb 2003 09:15:46 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: building hash
Message-Id: <b2af02$t6c$1@nets3.rz.RWTH-Aachen.DE>
Also sprach joeri:
> I have a 75 MB file consisting of lines that look like:
>
> S0973708 Other operation on meninges OS
> S0873517 Excision of lesion of brain meninges
> S0873177 Excision brain meninges lesion
> S1295875 Removal of lesion of brain meninge
>
> The first element on each line is some sort of ID, followed by a tab,
> followed by some string.
> I want to load these into a hash like so, assuming that IN is the filehandle
> associated with the above file:
>
> while(<IN>) {
> $string{$1}={$2} if $_ =~ /(.*)\t(.*)\n/;
> }
>
> This goes pretty fast at the start, but really slows down as the hash grows
> bigger. This
> is probably due to the fact that while assigning a value to a key, Perl
> checks to see if the key already
> exists. The question here is, if I'm sure that the keys I will be using for
> the hash are unique, so that there
> is no need to check if the key already exists, can I build a hash or
> something similar for quick
> lookup later more rapidly?
I think you have a misconception of how hashes work. Perl takes the key
and applies a so called hashing function to it that transforms the
string into an integer which is in the range of [0, num_slots - 1].
'S0973708' and 'S0873517' are different keys, but it is easily possible
that these two keys map to the same slot. This case is referred to as a
collision and needs to be resolved by rehashing or appending to a linear
list in this slot or some other common techniques.
The reason why your program slows down is merely the fact that storing
75meg in a hash takes a lot of memory. It might be the case that your
operating system has to swap some memory to disc to allocate new memory.
This takes time.
Also, it's quite intersting sometimes to print a hash in scalar context.
For instance:
$hash{$_} = 1 for 0 .. 100;
print scalar %hash;
__END__
84/128
which means: 128 slots are currently available (the hash grows when
necessary) and the 101 elements I stored in the hash are actually stored
in only 84 slots, so there were (101 - 84) collisions. The more of those
collisions you have the slower your hash gets. But still, this is not
the problem in your case. It's simply the memory.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 11 Feb 2003 09:28:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: building hash
Message-Id: <b2afon$jep$1@mamenchi.zrz.TU-Berlin.DE>
joeri <jvandervloet@hotmail.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I have a 75 MB file consisting of lines that look like:
>
> S0973708 Other operation on meninges OS
> S0873517 Excision of lesion of brain meninges
> S0873177 Excision brain meninges lesion
> S1295875 Removal of lesion of brain meninge
>
> The first element on each line is some sort of ID, followed by a tab,
> followed by some string.
> I want to load these into a hash like so, assuming that IN is the filehandle
> associated with the above file:
>
> while(<IN>) {
> $string{$1}={$2} if $_ =~ /(.*)\t(.*)\n/;
> }
>
> This goes pretty fast at the start, but really slows down as the hash grows
> bigger. This
> is probably due to the fact that while assigning a value to a key, Perl
> checks to see if the key already
This is unlikely. Access time to a hash is (almost) independent of
the number of entries.
> exists. The question here is, if I'm sure that the keys I will be using for
> the hash are unique, so that there
> is no need to check if the key already exists, can I build a hash or
> something similar for quick
> lookup later more rapidly?
The check for duplicates can't be avoided. Even if the keys you
enter are unique, the hash values may not be. A hash *must* check
for that.
I suppose the reason the program gets slow as the table fills is
that the machine starts swapping. Note that a hash is quite a bit
bigger than the total size of its keys and values.
Anno
------------------------------
Date: Tue, 11 Feb 2003 10:47:28 GMT
From: "joeri" <jvandervloet@hotmail.com>
Subject: Re: building hash
Message-Id: <4x42a.43760$Jd.5553@afrodite.telenet-ops.be>
Tassilo v. Parseval wrote:
> But still, this is not
> the problem in your case. It's simply the memory.
I have 512 MB of RAM on a windows 2000 machine. This means that storing
a file which has a size on disk of 75MB into a hash, will take more than
400 MB of memory?
J
------------------------------
Date: Tue, 11 Feb 2003 10:43:27 +0000
From: Daniel Bird <dbird@no-spam.sghms.ac.uk>
Subject: call subroutines from a different file
Message-Id: <3E48D3CF.1050208@no-spam.sghms.ac.uk>
Dear all,
I wish to call subroutines from a 'file'. eg:
script1.pl calls subroutine 'printlogo' from the file 'subroutines'. Can
anybody assist me in what is probably quite simple?
TIA
Best Regards,
Dan
------------------------------
Date: 11 Feb 2003 10:46:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: call subroutines from a different file
Message-Id: <b2akab$m80$2@mamenchi.zrz.TU-Berlin.DE>
Daniel Bird <dbird@no-spam.sghms.ac.uk> wrote in comp.lang.perl.misc:
> Dear all,
> I wish to call subroutines from a 'file'. eg:
>
> script1.pl calls subroutine 'printlogo' from the file 'subroutines'. Can
> anybody assist me in what is probably quite simple?
See perldoc perlmod.
Anno
------------------------------
Date: Tue, 11 Feb 2003 11:00:04 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Controlling order of precedence
Message-Id: <mplh4v8auq6q6pqttpn18g19s5kpokt8u8@4ax.com>
Martien Verbruggen wrote:
>$ perl -MO=Terse,exec -e '$result = (($a+$b) + (($c+$d)))'
>OP (0x80fc088) enter
>COP (0x8103000) nextstate
>SVOP (0x80f9308) gvsv GV (0x80ffeac) *a
>SVOP (0x80f9328) gvsv GV (0x80ffe94) *b
>BINOP (0x8102d38) add [1]
>SVOP (0x8102480) gvsv GV (0x80fff00) *c
>SVOP (0x8172bf8) gvsv GV (0x80ffec4) *d
>BINOP (0x8102ca0) add [2]
>BINOP (0x80f9378) add [3]
>SVOP (0x8102d60) gvsv GV (0x80fff0c) *result
>BINOP (0x80f92e0) sassign
>LISTOP (0x80fc038) leave [1]
>-e syntax OK
>
>which is identical to the same expression without any brackets. This
>output shows the internal operations perl goes through in execution
>order. First it puts a on the stack, then b, then it adds them,
>leaving the result on the stack. It then pushes c and d on the stack,
>adds them, and then adds the result of that with what was already on
>the stack (the result of a + b). It then assigns that to $result.
I'm new to this... I am familir with how FORTH works, so your
explanation is what I could have given blindfolded. What I don't get is
what those digits between brackets are on the lines that contain the
"add" opcode. A real stack wouldn't need them. So, what are they? Is
this actually a stack, or are those "register" numbers?
--
Bart.
------------------------------
Date: Tue, 11 Feb 2003 08:58:36 +0000
From: Simon Oliver <simon.oliver@nospam.umist.ac.uk>
Subject: Re: Data access with perl
Message-Id: <3E48BB3C.80605@nospam.umist.ac.uk>
Stephen Patterson wrote:
> Assuming $querystring contains the text of the SQL query, just adjust
> the field list of the query.
Alternatively (but not as efficient as restricting the SELECT statement)
explicitly name the columns you wish to display...
foreach $key( keys( %Data ) )
becomes
foreach $key( qw(name address) )
--
Simon Oliver
------------------------------
Date: Tue, 11 Feb 2003 06:55:16 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: decompress a tar.Z fine in perl
Message-Id: <pan.2003.02.11.05.50.59.119493@kamelfreund.de>
On Tue, 11 Feb 2003 04:49:57 +0000, Serial # 19781010 wrote:
> I am new to perl and need to extract files from a tar.Z file.
>
> using the archive::tar module i am able to get files from a tar and
> tar.gz but not tar.Z. When I attempt to decompress the tar.Z the
> binary contents of the file are dumpted to the screen.
>
> any help on the issues is greatly apperciated.
>
> I am using the following code to test.
Sorry, I couldn't find any obvious error in your code.
I just can only give some other hints :-(
>
> #!/bin/perl
>
use strict;
use warnings;
Perhaps Perl has an idea what went wrong and that's the only way to get an
idea about.
> use Archive::Tar;
>
> $engineFile = "vsapi6510rh.tar.Z";
Of course in strict mode,
you would now need
my $engine_file = "vsapi6510rh.tar.Z";
>
> $tarNewEngine = Archive::Tar->new($engineFile, 1);
The new method of Archive::Tar returns undef, if it couldn't read the
file. A way to check it is
my $tar_new_engine = Archive::Tar->new($engine_file, 1)
or die "Couldn't read engine file $engine_file: $!";
> @newFileList = $tarNewEngine->list_files();
>
> foreach $file ( @newFileList ){
> print("$file\n");
> }
A simpler way is
print join "\n", $tar_new_engine->list_files();
Best Wishes,
Janek
------------------------------
Date: 11 Feb 2003 08:23:59 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: decompress a tar.Z fine in perl
Message-Id: <slrnb4hcov.ltr.abigail@alexandra.abigail.nl>
Serial # 19781010 (mail@mail.net) wrote on MMMCDLI September MCMXCIII in
<URL:news:t00h4v8q92ahht8dsmb4csigj0jdemacje@4ax.com>:
** I am new to perl and need to extract files from a tar.Z file.
**
** using the archive::tar module i am able to get files from a tar and
** tar.gz but not tar.Z. When I attempt to decompress the tar.Z the
** binary contents of the file are dumpted to the screen.
**
** any help on the issues is greatly apperciated.
**
** I am using the following code to test.
**
** #!/bin/perl
**
** use Archive::Tar;
**
** $engineFile = "vsapi6510rh.tar.Z";
**
** $tarNewEngine = Archive::Tar->new($engineFile, 1);
** @newFileList = $tarNewEngine->list_files();
**
** foreach $file ( @newFileList ){
** print("$file\n");
** }
#!/usr/bin/perl
use strict;
use warnings;
my $engineFile = "vsapi6510rh.tar.Z";
my @newFileList = `zcat $engineFile | tar tf -`;
foreach my $file (@newFileList) {
...
}
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;
------------------------------
Date: Tue, 11 Feb 2003 00:08:43 -0500
From: Matthew Lockner <lockner@cse.psu.edu>
Subject: Re: How to Iterate through a String
Message-Id: <b2a0gr$1fca$1@f04n12.cac.psu.edu>
ibits wrote:
> Hi, this is newbee question
>
> I was wondering if somebody could show me an example of how to iterate
> through a string that someone has entered and print it out character
> by character to each new line.
> for eg She should print like
> S
> h
> e
>
Try the following (assumes the string is in $str):
print substr ($str, $_, 1), "\n" for (0 .. length ($str) - 1);
------------------------------
Date: Tue, 11 Feb 2003 05:24:46 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: How to Iterate through a String
Message-Id: <m52h4vovaotrsr3dpbpb0o6818euhmlibn@4ax.com>
On 10 Feb 2003 20:57:09 -0800, in comp.lang.perl.misc, one2katwo@yahoo.com (ibits) wrote:
>I was wondering if somebody could show me an example of how to iterate
>through a string that someone has entered and print it out character
>by character to each new line.
>for eg She should print like
>S
>h
>e
perl -e 'print join ("\n", (split "", $ARGV[0])), "\n"' She
--
Sharon
------------------------------
Date: Tue, 11 Feb 2003 01:10:18 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to Iterate through a String
Message-Id: <3E4893CA.BF3A4D42@earthlink.net>
ibits wrote:
>
> Hi, this is newbee question
>
> I was wondering if somebody could show me an example of how to iterate
> through a string that someone has entered and print it out character
> by character to each new line.
> for eg She should print like
> S
> h
> e
while(<>) {
print $_, "\n" for split //;
}
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: Tue, 11 Feb 2003 17:09:11 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: How to Iterate through a String
Message-Id: <dJ12a.1$Vu3.3556@vicpull1.telstra.net>
"ibits" <one2katwo@yahoo.com> wrote in message
news:a317f43d.0302102057.78d93acb@posting.google.com...
> Hi, this is newbee question
>
> I was wondering if somebody could show me an example of how to iterate
> through a string that someone has entered and print it out character
> by character to each new line.
> for eg She should print like
> S
> h
> e
$, = "\n";
print split //, She;
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Tue, 11 Feb 2003 07:07:54 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Quick regexp question
Message-Id: <Xns931F521102BF5elhber1lidotechnet@62.89.127.66>
Abigail wrote:
> Bernard El-Hagin (bernard.el-hagin@DODGE_THISlido-tech.net) wrote on
> MMMCDL September MCMXCIII in
> <URL:news:Xns931E494502E4Delhber1lidotechnet@62.89.127.66>: __
> Abigail wrote: __
> __ > Bernard El-Hagin (bernard.el-hagin@DODGE_THISlido-tech.net) wrote
> on __ > MMMCDXLVII September MCMXCIII in
> __ > <URL:news:Xns931B7C6D5A13Belhber1lidotechnet@62.89.127.66>: []
> __ > Sandman wrote: []
> __ > [] > I have four string:
> __ > [] >
> __ > [] > Managing director: John Jensen
> __ > [] > Supreme VP: Tim Adams
> __ > [] > Sales key person: Math Edwards
> __ > [] > Junk: Junk
> __ > [] >
> __ > [] > And I am in a while that has one of the above in $_. Now, I
> would __ > like [] > to remove everything up to the :-character, if it
> contains __ > two or [] > three words (i.e. not 'Junk: Junk'). First I
> did a: __ > [] >
> __ > [] > s/^(.*?)://;
> __ > [] > $title=$1;
> __ > []
> __ > []
> __ > [] If I understand correctly, all you have to do is make the
> match __ > greedy. []
> __ > [] s/^(.*)://;
> __ > [] $title = $1;
> __ >
> __ > Did you try?
> __
> __
> __ Yes I did. It worked for me _as I understood the problem_.
>
> Really? Did you try the example the OP gave? Did your suggestion leave
> 'Junk: Junk' alone, as specified?
>
> __ I made
> it __ clear that I may not have understood the problem with the words
> "If I __ understand correctly". If there's any part of that you
> didn't understand __ let me know and I'll walk you through it.
>
> Right. I don't understand how 's/^(.*)://;' leaves 'Junk: Junk' alone.
> I can't reproduce that in any version of Perl I have. Please walk me
> through your solution.
I understood that the OP wanted to keep in $title everything up to the
last ':' in the line. I misunderstood the problem and I made it clear
that I may have done so. Do you get it now? I can draw you a picture if
you don't. JPEG, GIF, TIFF, BMP, whatever. I'm flexible.
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Tue, 11 Feb 2003 07:08:34 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Quick regexp question
Message-Id: <Xns931F522D64E90elhber1lidotechnet@62.89.127.66>
David H. Adler wrote:
> In article <Xns931E494502E4Delhber1lidotechnet@62.89.127.66>, Bernard
> El-Hagin wrote:
>> Abigail wrote:
>>
>>> Bernard El-Hagin (bernard.el-hagin@DODGE_THISlido-tech.net) wrote on
>>> MMMCDXLVII September MCMXCIII in
>>
>> Sarcasm is so last Tuesday.
>
> Oh, it came back in on friday. You must not be on the list. :-)
I wish *somebody* would keep me posted! :-)
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Tue, 11 Feb 2003 06:50:50 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Request help with this script
Message-Id: <3e489a4f.140978095@news.erols.com>
julia4_me@yahoo.com (Julia Briggs) wrote:
: Hello! I've got this simple script that works just fine, but I'm
: looking for any suggestions on how to improve... mainly what I desire
: is to make sure that some hacker can't mess with it. Any
: suggestions/ideas on how best to reinforce this script??
[snip]
: foreach ($query->param){
: if ($query->param($_)){ ## The user entered some value!!
: if (/^file_attached_[A-Z]$/){ ## The uploaded file!!
: ++$no_of_files;
: push(@list,$_);
: }else{ ## One of the other items (Sender's Name, Sender's Email, etc...).
: ## Store the value in a variable.
: ## The name of the variable is the same as the HTML form element name
: ## Eg if the HTML element is called name_sender, the PERL
: ## variable will be called $name_sender.
: $$_=$query->param($_);
: }
: }
: }
: open(MAIL, "| $mailprog -t ");
Somebody last week asked for help with a largely identical program.
Where did this code coming from?
Whoever is giving this code away doesn't have a grasp of fundamental
security issues. For the most benign exploit, it is trivially
compromised into becoming a spam gateway.
More harmful but equally trivial, a person can use this code to run
any program he wants on your machine.
Do not use this code. If it is up and running, remove it immediately.
------------------------------
Date: Tue, 11 Feb 2003 09:59:56 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: strict and warnings
Message-Id: <wQ32a.10539$LY2.628422@newsc.telia.net>
I'm wondering to which extent
use strict;
use warnings;
add any overhead when compiling and executing a Perl program.
They are indeed useful when *developing* a program, but should they
always be left in a *production* copy?
As regards 'use warnings;', I never leave it if portability is an issue
(doesn't work in the earlier Perl5 versions), but sometimes I include
$^W = 1;
instead.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 11 Feb 2003 10:22:54 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: strict and warnings
Message-Id: <b2aitu$469$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Gunnar Hjalmarsson:
> I'm wondering to which extent
>
> use strict;
> use warnings;
>
> add any overhead when compiling and executing a Perl program.
Negligible. Strictures have three components of which two ('vars' and
'subs') work solely at compile-time. After the compilation phase the
run-time should be identical.
Strict references (the only third of strictures that work at runtime)
check that you do not use symbolic references. They set a certain
bitmask in $^H. I am pretty positive that this bitmask is internally
tested against no matter whether you use strictures or not. Just have a
look at strict.pm. I am sure these 27 lines of code do not do any harm.
Warnings (that aren't fatal) at least add a little overhead by printing
something to STDERR:
print undef for 0 .. 10_000;
is likely to be much slower when warnings are on. Ideally, a good
program doesn't rise warnings.
> They are indeed useful when *developing* a program, but should they
> always be left in a *production* copy?
As for strictures, I think they should. If you take them out and a
situation arises where strictures would have complained, I am sure your
program no longer functions as expected anyway.
Warnings can be taken out but best is you make sure that during
production you weed out all of them or be sure that any warnings that
potentially occur are harmless.
> As regards 'use warnings;', I never leave it if portability is an issue
> (doesn't work in the earlier Perl5 versions), but sometimes I include
>
> $^W = 1;
>
> instead.
Why not use the -w switch on the shebang-line? Anyway, the
warnings-pragma and $^W don't do the same thing. The first has a
much finer granularity since it only affects the current package and can
be block-scoped while -w (or $^W which is the same) are global and will
even raise warnings in modules you use.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 10 Feb 2003 21:58:57 -0800
From: mjp@pilcrow.madison.wi.us (Michael Pomraning)
Subject: threaded File::Glob, static GLOB_ERROR semantics
Message-Id: <a2c51894.0302102158.6417b7ea@posting.google.com>
In v5.8.0, File::Glob uses a single, static XS variable to store the
return value of its underlying doglob() calls, accessible via
GLOB_ERROR(). Multiple threads must therefore synchronize both their
globbing and their error-checking, if they are to safely determine
their own GLOB_ERROR status:
{ lock($some_mutex); bsd_glob($pattern); $err = GLOB_ERROR; }
if ($err) { ... }
or similar.
Are these semantics desirable? I had expected a thread-specific
GLOB_ERROR() return, not unlike pthread's thread-specific errno.
-Mike
------------------------------
Date: Tue, 11 Feb 2003 00:29:42 -0500
From: Matthew Lockner <lockner@cse.psu.edu>
Subject: Variation on iterating through a string
Message-Id: <b2a1o6$19n0$1@f04n12.cac.psu.edu>
I'd like to request from the masters a slight variation on the previous
problem, of which I have occasionally found myself in need.
A function, which takes a string as an argument, and returns a list of the
characters in that string (in order) - much like ML's explode function.
Preferably in a "most idiomatic Perl" version, and a "Perl golf" version.
The language being what it is, I find it hard to believe repeated calls to
substr are really the best way ("best" not necessarily being "clearest").
Thanks,
MJL
------------------------------
Date: Tue, 11 Feb 2003 01:08:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Variation on iterating through a string
Message-Id: <3E489378.7FA0EF38@earthlink.net>
Matthew Lockner wrote:
>
> I'd like to request from the masters a slight variation on the
> previous problem, of which I have occasionally found myself in need.
>
> A function, which takes a string as an argument, and returns a list of
> the characters in that string (in order) - much like ML's explode
> function.
> Preferably in a "most idiomatic Perl" version, and a "Perl golf"
> version.
> The language being what it is, I find it hard to believe repeated
> calls to substr are really the best way ("best" not necessarily being
> "clearest").
my @letters = split //, $string;
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: Tue, 11 Feb 2003 06:26:29 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Variation on iterating through a string
Message-Id: <pI02a.35$rE3.18@nwrddc01.gnilink.net>
Matthew Lockner wrote:
> A function, which takes a string as an argument, and returns a list
> of the characters in that string (in order) -
Is there anything wrong with the Perl builtin function 'split'?
jue
------------------------------
Date: Tue, 11 Feb 2003 06:01:06 -0000
From: lofstrom@lava.net (Karen Lofstrom)
Subject: Re: Why won't my for loop work?
Message-Id: <v4h4d2g47oqmbb@corp.supernews.com>
This is addressed to all of you who followed-up and emailed: THANKS.
I now have several versions of programs to do what I want, and I can
usefully contemplate the differences between them and the vast distance
that separates them from my first attempt.
All of you were confused by aspects of my syntax -- well, that was blind
guessing that something that worked in Java would work in Perl (hence + as
the concatenation operator) or something that worked in UNIX would work in
Perl (>> for redirecting output to a file). I thought I'd guessed right
when I got the program to compile, but clearly I hadn't.
I was using chop instead of chomp because my beginner's Perl book is old;
1996. Chomp must be new and improved. I supposed I should have bought a
more recent intro book rather than borrowing an old one.
Whew! This semester I'm trying to improve my Solaris and Linux skills, do
a tutorial in Discrete Math, learn more Java, take statistics, AND learn
Perl. I wonder how much I can do before my head explodes ...
--
Karen Lofstrom lofstrom@lava.net
----------------------------------------------------------------------
Because I could not stop for Death
He kindly left a message on my voice mail system -- Bryan O'Sullivan
------------------------------
Date: Tue, 11 Feb 2003 10:43:14 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Why won't my for loop work?
Message-Id: <3e48d144.340936010@news.cis.dfn.de>
On Tue, 11 Feb 2003 06:01:06 -0000, lofstrom@lava.net (Karen
Lofstrom) wrote:
>I was using chop instead of chomp because my beginner's Perl book is old;
>1996. Chomp must be new and improved.
It is. Chomp removes the last character. Chop removes
linebreaks from the end.
See 'perldoc -f chop' and 'perldoc -f chomp' for details
> I supposed I should have bought a
>more recent intro book rather than borrowing an old one.
Well, everybody makes mistakes.
>Whew! This semester I'm trying to improve my Solaris and Linux skills, do
>a tutorial in Discrete Math, learn more Java, take statistics, AND learn
>Perl. I wonder how much I can do before my head explodes ...
The most useful tool for learning Perl is the Perl
documentation that comes packaged with every
distribution of perl. The documentation is in so-called
.pod format (Plain Old Documentation) that is easily
convertable to text with pod2text or HTML using pod2html.
The Activestate distribution of Perl, available for Windows,
Linux and Solaris, comes with the documentation in
HTML format as well as pod format.
The docs come with a little program named perldoc
that is used for browsing and searching the documentation.
Some dislike it and use their own, but it is a good place
to start.
The three most useful switches for perldoc are:
-q (query, look up a keyword in the FAQs)
-f (function, look up a function)
-X (look up the docs for a module)
You can also use it to look up a document directly.
Here are a few useful documents to start with:
perldoc perl
perldoc perldoc # perldoc and how to use it
perldoc perlrun # command line switches etc
perldoc perlsyn # syntax
perldoc perlrequick # quick guide to regular expressions
perldoc perlstyle # style guide
perldoc perlfaq1 # FAQ number 1 (go up to 9)
I hope this helps.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: 11 Feb 2003 10:45:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why won't my for loop work?
Message-Id: <b2ak7f$m80$1@mamenchi.zrz.TU-Berlin.DE>
Helgi Briem <helgi@decode.is> wrote in comp.lang.perl.misc:
> On Tue, 11 Feb 2003 06:01:06 -0000, lofstrom@lava.net (Karen
> Lofstrom) wrote:
>
> >I was using chop instead of chomp because my beginner's Perl book is old;
> >1996. Chomp must be new and improved.
>
> It is. Chomp removes the last character. Chop removes
> linebreaks from the end.
Correct, except it's the other way 'round :)
Anno
------------------------------
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 4548
***************************************