[29007] in Perl-Users-Digest
Perl-Users Digest, Issue: 251 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 22 03:09:56 2007
Date: Thu, 22 Mar 2007 00:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 22 Mar 2007 Volume: 11 Number: 251
Today's topics:
A twist on Cookbook recipe 4.6 <perl4hire@softouch.on.ca>
Re: A twist on Cookbook recipe 4.6 <ben@morrow.me.uk>
Re: A twist on Cookbook recipe 4.6 <someone@example.com>
any easy way to print a few tables in the same rows? <robertchen117@gmail.com>
getting DBI and ODBC to work with PERL and MYSQL data s <jack_posemsky@yahoo.com>
my $session = new CGI::Session() <kmhuntly@gmail.com>
Re: Need help understanding how a file input block work <tadmc@augustmail.com>
Re: Net::Telnet Error handling/trapping <tadmc@augustmail.com>
Re: Net::Telnet Error handling/trapping <tadmc@augustmail.com>
new CPAN modules on Thu Mar 22 2007 (Randal Schwartz)
Re: perl feature request <tadmc@augustmail.com>
Re: perl feature request <ben@morrow.me.uk>
split function learnperlscripting@gmail.com
Re: split function <uri@stemsystems.com>
Re: split function <ben@morrow.me.uk>
Re: split function <spamtrap@dot-app.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Mar 2007 21:22:08 -0400
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: A twist on Cookbook recipe 4.6
Message-Id: <0RkMh.8392$_f.3875@read2.cgocable.net>
I'm stuck trying to get a count of duplicate emails in a HoH.
Input is a pipe-delimited file of users with their email addresses.
Element 0 is a unique ID number; 10 is their email.
The problem is some users are present multiple times, so that their ID
number is unique but their email remains the same.
I'm trying to prepend a string to the duplicated emails, so I can use
them to populate a MySQL table along with the ID numbers. The email
addresses will not (likely) work. Not my problem.
What I have is a working script from the 'Perl Cookbook' (recipe #4.6)
that shows me which emails are duplicated.
I'm trying to get a count of those emails ALONG with their respective IDs.
My attempts so far:
#! /usr/bin/perl
use strict;
use warnings;
my ($ID,$Email);
my %SeenEmails=();
open IN,"<",$InFile or die "Can't open $InFile: $!\n";
foreach my $line (<IN>)
{
($ID,$Email) = ((split /\|/, $line)[0,10]);
$SeenEmails{$Email}++;
}
close IN or die "Can't close $InFile: $!\n";;
for (sort keys %SeenEmails)
{
if ($SeenEmails{$_} > 1)
{
print "$_ -> $SeenEmails{$_}\n";
for my $i (1..($SeenEmails{$_}-1))
{
my $thisone=$_;
$thisone = 'dupe' . $i . '_' . $_;
print "\t$thisone\n";
}
}
}
This prepends the email with a dynamically generated string, but I'm
missing the ID number when I populate the hash initially.
If I use
$SeenEmails{$ID}{$Email}++;
I get the ID number, but I'm counting the wrong thing.
How can I get the duplicated emails (and how many there are) with their
respective IDs, so I can prepend my string?
--
Amer Neely
w: www.softouch.on.ca/
------------------------------
Date: Thu, 22 Mar 2007 01:54:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: A twist on Cookbook recipe 4.6
Message-Id: <1849d4-lqb.ln1@osiris.mauzo.dyndns.org>
Quoth Amer Neely <perl4hire@softouch.on.ca>:
>
> I'm trying to get a count of those [duplicated] emails ALONG with
> their respective IDs.
>
> My attempts so far:
>
> #! /usr/bin/perl
> use strict;
> use warnings;
>
> my ($ID,$Email);
Don't declare variables before you need them. These should go inside the
loop.
> my %SeenEmails=();
>
> open IN,"<",$InFile or die "Can't open $InFile: $!\n";
I would suggest
open my $IN, ...
instead. Global filehandles are as bad as any other global variable.
> foreach my $line (<IN>)
This will work, but is a terrible waste of time. <FH> in list context
returns a list of lines, so you are reading in the file, splitting that
into lines, and then going through them one at a time. If you want to go
through one at a time, use while instead:
while (my $line = <IN>) {
> {
> ($ID,$Email) = ((split /\|/, $line)[0,10]);
> $SeenEmails{$Email}++;
Here you want to store a list of the IDs, instead of just incrementing.
Something like
$SeenEmails{$Email} ||= [];
push @{ $SeenEmails{$Email} }, $ID;
which could be shortend to
push @{ $SeenEmails{$Email} ||= [] }, $ID;
once you're comfortable with the syntax.
If you don't understand refs (the [] and @{...} stuff) read perldoc
perlreftut.
> }
> close IN or die "Can't close $InFile: $!\n";;
>
> for (sort keys %SeenEmails)
> {
> if ($SeenEmails{$_} > 1)
my $seen = $SeenEmails{$_};
if (@$seen > 1) {
I don't really understand what you want to generate from this, but
perhaps you want something like
print "$_ -> " . scalar(@$seen) . "\n";
for my $id (@$seen) {
print "\tdupe${id}_$_\n";
}
That print string is quite complicated; it can be split into
"\t" . 'dupe' . $id . '_' . $_ . "\n"
. A decent highlighting editor will help, of course.
FWIW, while I often use $_ as an implicit 'for' loop variable, I only
use it on the *innermost* loop. I find that once a loop gets large
enough to have sub-loops of its own, it probably deserves a real
variable; and having a $_ around that isn't 'the current item' is
unhelpful and confusing :).
> {
> print "$_ -> $SeenEmails{$_}\n";
> for my $i (1..($SeenEmails{$_}-1))
> {
> my $thisone=$_;
> $thisone = 'dupe' . $i . '_' . $_;
> print "\t$thisone\n";
> }
> }
> }
Ben
--
2 + 2 = 5 for sufficiently large values of 2
[ben@morrow.me.uk]
------------------------------
Date: Thu, 22 Mar 2007 05:00:29 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: A twist on Cookbook recipe 4.6
Message-Id: <N3oMh.583$6z3.538@edtnps82>
Ben Morrow wrote:
>
> Quoth Amer Neely <perl4hire@softouch.on.ca>:
>>
>> {
>> ($ID,$Email) = ((split /\|/, $line)[0,10]);
>> $SeenEmails{$Email}++;
>
> Here you want to store a list of the IDs, instead of just incrementing.
> Something like
>
> $SeenEmails{$Email} ||= [];
> push @{ $SeenEmails{$Email} }, $ID;
>
> which could be shortend to
>
> push @{ $SeenEmails{$Email} ||= [] }, $ID;
All you really need is:
push @{ $SeenEmails{ $Email } }, $ID;
(Lookup autovivification in the docs.)
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: 21 Mar 2007 23:08:01 -0700
From: "robertchen117@gmail.com" <robertchen117@gmail.com>
Subject: any easy way to print a few tables in the same rows?
Message-Id: <1174543681.425674.16280@e65g2000hsc.googlegroups.com>
all my tables maybe just two columns, I used this:
my $cgi = new CGI;
print $cgi->th("OS Type");
print $cgi->th("Version");
...
A lot of tables printed like the same way above.
Using the CGI default th, td methods will output tables just all way
through down the page...
any easy way to print a few tables in the same rows?
------------------------------
Date: 21 Mar 2007 21:07:45 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: getting DBI and ODBC to work with PERL and MYSQL data source
Message-Id: <1174536465.609074.76150@e1g2000hsg.googlegroups.com>
Hi folks,
On windows server 2003 I installed the Mysql ODBC driver, created a
dsn, and installed DBI and DBD::ODBC perl modules. Does anyone have
experience issuing a SQL query through PERL to Mysql.. here is my
program, the uncommented pieces worked great but when I remove the
comments for the bottom 2 rows I get the error indicated:
use DBD::ODBC;
use strict;
use diagnostics;
use DBI;
eval {
my $dbh = DBI->connect('DBI:ODBC:mysqldsn;host=localhost;', 'root',
's1ghtspr1ng7281',
{ 'RaiseError' => 1, 'PrintError' => 0, 'AutoCommit' => 0} );
}; # eval
# $sth = $dbh->prepare("SELECT testcol1 FROM temptable");
# $sth->execute( $baz );
ERROR:
E:\tmp>perl odbc_test2.pl
Global symbol "$sth" requires explicit package name at odbc_test2.pl
line 14.
Global symbol "$dbh" requires explicit package name at odbc_test2.pl
line 14.
Global symbol "$sth" requires explicit package name at odbc_test2.pl
line 15.
Global symbol "$baz" requires explicit package name at odbc_test2.pl
line 15.
Execution of odbc_test2.pl aborted due to compilation errors (#1)
(F) You've said "use strict vars", which indicates that all
variables
must either be lexically scoped (using "my"), declared beforehand
using
"our", or explicitly qualified to say which package the global
variable
is in (using "::").
Uncaught exception from user code:
Global symbol "$sth" requires explicit package name at
odbc_test2.pl lin
e 14.
Global symbol "$dbh" requires explicit package name at odbc_test2.pl
line 14.
Global symbol "$sth" requires explicit package name at odbc_test2.pl
line 15.
Global symbol "$baz" requires explicit package name at odbc_test2.pl
line 15.
Execution of odbc_test2.pl aborted due to compilation errors.
at odbc_test2.pl line 16
------------------------------
Date: 21 Mar 2007 18:34:06 -0700
From: "Kevin" <kmhuntly@gmail.com>
Subject: my $session = new CGI::Session()
Message-Id: <1174527246.530096.188950@o5g2000hsb.googlegroups.com>
When I try to initialize a CGI session with my $session = new
CGI::Session(), my script hangs and eventually throws a CGI timeout.
This actually occurs when trying to create a new anything, be it
session, or CGI, or anything. Any thoughts?
------------------------------
Date: Wed, 21 Mar 2007 21:22:22 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need help understanding how a file input block works
Message-Id: <slrnf03q2u.m7.tadmc@tadmc30.august.net>
Paul <tester.paul@gmail.com> wrote:
> Basically, it's a normal text file with a bunch of sections
> that have
...
> followed by a dash line separator.
Then you might also what to read up on the $/ variable in:
perldoc perlvar
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 21 Mar 2007 20:44:34 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <slrnf03ns2.m7.tadmc@tadmc30.august.net>
Abigail <abigail@abigail.be> wrote:
> Uri Guttman (uri@stemsystems.com) wrote on MMMMCML September MCMXCIII in
><URL:news:x7lkhqfxec.fsf@mail.sysarch.com>:
>`` >>>>> "CG" == Chris G <nospam@example.com> writes:
> ``
> `` CG> I am sorry that the group is so intolerant of top-posting, but how I
> `` CG> post it my choice, just others have a choice to respond or not. This is
> `` CG> not a flame, just a statement of fact. In the interest of not further
> `` CG> polluting the ng with non-perl postings, this is the last I will comment
> `` CG> on it. Let's just agree to disagree and move on.
> ``
> `` it is not intolerant. it has been know for decades that interpersed
> `` edited quotes are much better for technical discussion as they are
> `` commonly q&a. do you want answers before the questions?
>
>
> Yeah, but the same holds for proper use of capitals.
Amen!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 21 Mar 2007 20:42:16 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <slrnf03nno.m7.tadmc@tadmc30.august.net>
Chris G. <nospam@example.com> wrote:
> I am sorry that the group is so intolerant of top-posting, but how I
> post it my choice, just others have a choice to respond or not. This is
> not a flame, just a statement of fact.
I am sorry that everyone is so intolerant of farting at the dinner table,
but how I pass gas is my choice, just others have a choice to respond
or not. This is not a flame (unless you hold a match near my butt),
just a statement of fact.
> Let's just agree to disagree and move on.
I agree to never see any of your posts again.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 22 Mar 2007 04:42:13 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Mar 22 2007
Message-Id: <JFAFqD.1w42@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
AI-Prolog-0.736
http://search.cpan.org/~jjore/AI-Prolog-0.736/
Perl extension for logic programming.
----
AI-Prolog-0.737
http://search.cpan.org/~jjore/AI-Prolog-0.737/
Perl extension for logic programming.
----
Algorithm-Merge-0.07
http://search.cpan.org/~jsmith/Algorithm-Merge-0.07/
Three-way merge and diff
----
Apache2-Translation-0.13
http://search.cpan.org/~opi/Apache2-Translation-0.13/
Configuring Apache dynamically
----
App-Addex-0.001
http://search.cpan.org/~rjbs/App-Addex-0.001/
----
Audio-MPD-0.15.3
http://search.cpan.org/~jquelin/Audio-MPD-0.15.3/
Class for talking to MPD (Music Player Daemon) servers
----
B-Deobfuscate-0.18
http://search.cpan.org/~jjore/B-Deobfuscate-0.18/
Deobfuscate source code
----
Carp-Always-0.08
http://search.cpan.org/~ferreira/Carp-Always-0.08/
Warns and dies noisily with stack backtraces
----
Catalyst-Plugin-OrderedParams-0.06
http://search.cpan.org/~agrundma/Catalyst-Plugin-OrderedParams-0.06/
Maintain order of submitted form parameters
----
Email-ARF-0.001
http://search.cpan.org/~rjbs/Email-ARF-0.001/
abuse report format (placeholder module)
----
Getopt-Mixed-1.10
http://search.cpan.org/~cjm/Getopt-Mixed-1.10/
getopt processing with both long and short options
----
HTML-Copy-1.13
http://search.cpan.org/~tkurita/HTML-Copy-1.13/
copy a HTML file without breaking links.
----
Handel-0.99_17
http://search.cpan.org/~claco/Handel-0.99_17/
A cart/order/checkout framework with AxKit/TT/Catalyst support
----
Image-Pngslimmer-0.20
http://search.cpan.org/~acmcmen/Image-Pngslimmer-0.20/
slims (dynamically created) PNGs
----
Locale-Maketext-Gettext-1.18
http://search.cpan.org/~imacat/Locale-Maketext-Gettext-1.18/
Joins the gettext and Maketext frameworks
----
Mail-SpamAssassin-SimpleClient-0.001
http://search.cpan.org/~rjbs/Mail-SpamAssassin-SimpleClient-0.001/
easy client to SpamAssassin's spamd
----
Net-MirapointAdmin-3.04
http://search.cpan.org/~ahall/Net-MirapointAdmin-3.04/
Perl interface to the Mirapoint administration protocol
----
Net-SFTP-Foreign-0.90_17
http://search.cpan.org/~salva/Net-SFTP-Foreign-0.90_17/
Secure File Transfer Protocol client
----
POE-Component-Server-FTP-0.07
http://search.cpan.org/~xantus/POE-Component-Server-FTP-0.07/
Event-based FTP server on a virtual filesystem
----
POE-Component-Server-SimpleHTTP-1.22
http://search.cpan.org/~bingos/POE-Component-Server-SimpleHTTP-1.22/
Perl extension to serve HTTP requests in POE.
----
POE-Component-Server-SimpleHTTP-1.23
http://search.cpan.org/~bingos/POE-Component-Server-SimpleHTTP-1.23/
Perl extension to serve HTTP requests in POE.
----
Params-Smart-0.08
http://search.cpan.org/~rrwo/Params-Smart-0.08/
use both positional and named arguments in a subroutine
----
Parse-QTEDI-0.02_01
http://search.cpan.org/~dongxu/Parse-QTEDI-0.02_01/
Parse QT/KDE preprocessed headers
----
Perlbal-1.55
http://search.cpan.org/~bradfitz/Perlbal-1.55/
Reverse-proxy load balancer and webserver
----
ProgressMonitor-0.03
http://search.cpan.org/~knth/ProgressMonitor-0.03/
a flexible and configurable framework for providing feedback on how a long-running task is proceeding.
----
SQL-Tidy-0.01
http://search.cpan.org/~dmitri/SQL-Tidy-0.01/
tidy up SQL statements.
----
SVK-Churn-0.05
http://search.cpan.org/~gugod/SVK-Churn-0.05/
----
Taint-Util-0.04
http://search.cpan.org/~avar/Taint-Util-0.04/
Test for and flip the taint flag without regex matches or eval
----
Template-Process-0.0005
http://search.cpan.org/~ferreira/Template-Process-0.0005/
Process TT2 templates against data files
----
Template-Recall-0.02
http://search.cpan.org/~gilad/Template-Recall-0.02/
"Reverse callback" templating system
----
Test-Group-0.07
http://search.cpan.org/~domq/Test-Group-0.07/
Group together related tests in a test suite
----
Text-OutputFilter-0.11
http://search.cpan.org/~hmbrand/Text-OutputFilter-0.11/
Enable post processing of output without fork
----
Text-Wrapper-1.01
http://search.cpan.org/~cjm/Text-Wrapper-1.01/
Simple word wrapping routine
----
Voting-Condorcet-RankedPairs-1.00
http://search.cpan.org/~pjf/Voting-Condorcet-RankedPairs-1.00/
Ranked Pairs voting resolution.
----
Voting-Condorcet-RankedPairs-1.01
http://search.cpan.org/~pjf/Voting-Condorcet-RankedPairs-1.01/
Ranked Pairs voting resolution.
----
WWW-Dict-TWMOE-Phrase-0.05
http://search.cpan.org/~gugod/WWW-Dict-TWMOE-Phrase-0.05/
TWMOE Chinese Phrase Dictionary interface.
----
Wx-0.70
http://search.cpan.org/~mbarbon/Wx-0.70/
interface to the wxWidgets cross-platform GUI toolkit
----
Wx-Demo-0.06
http://search.cpan.org/~mbarbon/Wx-Demo-0.06/
the wxPerl demo
----
oEdtk.20070321.v0.31
http://search.cpan.org/~daunay/oEdtk.20070321.v0.31/
----
parrot-0.4.10
http://search.cpan.org/~coke/parrot-0.4.10/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 21 Mar 2007 20:50:47 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl feature request
Message-Id: <slrnf03o7n.m7.tadmc@tadmc30.august.net>
dt <ppc@cheapbooks.com> wrote:
> if ($html !~ /./)
> {
> $html = load_as_string($fh, "filename.html");
> }
> if the var is not set, it sets the
> var. if it is set, it skips the call.
But it would *not* skip the call if
$html = "\n";
...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 22 Mar 2007 01:31:43 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perl feature request
Message-Id: <vs29d4-jlb.ln1@osiris.mauzo.dyndns.org>
Quoth anno4000@radom.zrz.tu-berlin.de:
> Ben Morrow <ben@morrow.me.uk> wrote in comp.lang.perl.misc:
> >
> > I was going to say 'in 5.10 this exact feature has been included, as the
> > new 'state' variables', but perlsub says
> >
> > | B<Caveat>: the code at the right side of the assignment to a state
> > | variable will be executed every time; only the assignment is disabled.
> > | So, avoid code that has side-effects, or that is slow to execute. This
> > | might be optimized out in a future version of Perl.
> >
> > Doesn't this make state variables, uh, rather useless? Given that they
> > are basically exactly equivalent to your example above, so all you save
> > is one compile-time block? Have I missed something?
>
> No, they're not useless because they keep their value from one call to
> another, while still being lexical variables. Currently, we must
> declare a lexical variable outside the sub for that purpose.
Yes, I realise that. What I was saying is that if
sub foo {
state $foo;
...;
}
is equivalent to
{
my $foo;
sub foo {
...;
}
}
is this really terribly useful? I suppose if you had something like
sub foo {
# lotsa stuff
{
state $foo;
...;
}
}
then you've gained a decrease in scope, but why not just use another
sub? Is there some other use case I'm missing?
Ben
--
#!/bin/sh
quine="echo 'eval \$quine' >> \$0; echo quined"
eval $quine
# [ben@morrow.me.uk]
------------------------------
Date: 21 Mar 2007 20:42:07 -0700
From: learnperlscripting@gmail.com
Subject: split function
Message-Id: <1174534927.524055.25570@e1g2000hsg.googlegroups.com>
I am having a hard time understanding this perl scripting code:
while (<STDIN>) {
chomp;
($user, $gcos) = (split /:/) [0, 4];
($real) = split(/,/, $gcos);
print "$user is $real \n";
}
i do not understand line 3 and 4. could someone please help me out.
much appreciated.
------------------------------
Date: Wed, 21 Mar 2007 23:02:44 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: split function
Message-Id: <x7zm669b8b.fsf@mail.sysarch.com>
>>>>> "l" == learnperlscripting <learnperlscripting@gmail.com> writes:
l> I am having a hard time understanding this perl scripting code:
l> while (<STDIN>) {
l> chomp;
l> ($user, $gcos) = (split /:/) [0, 4];
l> ($real) = split(/,/, $gcos);
l> print "$user is $real \n";
l> }
l> i do not understand line 3 and 4. could someone please help me out.
l> much appreciated.
split is well documented. run this command:
perldoc -f split
why is your nick learnperlscripting? are you learning perl or offering
to others to learn perl
if you are learning perl you should first learn to look for help in
perl's docs. all the functions and ops are fully documented there.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 22 Mar 2007 04:00:28 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: split function
Message-Id: <sjb9d4-smc.ln1@osiris.mauzo.dyndns.org>
Quoth learnperlscripting@gmail.com:
> I am having a hard time understanding this perl scripting code:
>
> while (<STDIN>) {
> chomp;
> ($user, $gcos) = (split /:/) [0, 4];
This line first calls the split function: perldoc -f split. It's in list
context (we'll see why in a minute), and it defaults to splitting the
string in $_ that we've just read from STDIN.
The (...)[0,4] is a list slice (perldoc perldata, section "Slices"),
which selects the first and fifth of the items returned by split.
These two values are then assigned to the variables $user and $gecos
respectively.
> ($real) = split(/,/, $gcos);
This is another split, this time specifying what string to split. The
first result is assigned to the variable $real.
> print "$user is $real \n";
> }
>
> i do not understand line 3 and 4. could someone please help me out.
> much appreciated.
The program looks like a rather poor attempt at parsing a Unix passwd
file. There are at least two bugs: the GECOS field should be split on
the pattern /\s*,\s*/ instead, and the real name needs any instance of
'&' replaced with an initial-caps version of $user. The program is not
'strict'-safe: have you read the Posting Guidelines for this group yet?
Also, if it is intended to parse the real /etc/passwd file, it would be
much better to use the getpwent functions and the User::pwent module, so
it works properly on systems that use other passwd facilities such as
NIS.
Ben
--
Raise your hand if you're invulnerable.
[ben@morrow.me.uk]
------------------------------
Date: Thu, 22 Mar 2007 00:05:01 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: split function
Message-Id: <m2648tditu.fsf@local.wv-www.com>
learnperlscripting@gmail.com writes:
> I am having a hard time understanding this perl scripting code:
>
> while (<STDIN>) {
> chomp;
> ($user, $gcos) = (split /:/) [0, 4];
> ($real) = split(/,/, $gcos);
> print "$user is $real \n";
> }
>
> i do not understand line 3 and 4. could someone please help me out.
Have a look at "perldoc -f split".
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 251
**************************************