[28338] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9702 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 8 06:05:46 2006

Date: Fri, 8 Sep 2006 03:05:04 -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           Fri, 8 Sep 2006     Volume: 10 Number: 9702

Today's topics:
        [ANNOUNCE] Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: beginners question <someone@example.com>
    Re: beginners question <xicheng@gmail.com>
    Re: beginners question <nospam@diespammer.com>
    Re: beginners question <nospam@diespammer.com>
    Re: beginners question <abigail@abigail.be>
    Re: beginners question <josef.moellers@fujitsu-siemens.com>
    Re: beginners question <josef.moellers@fujitsu-siemens.com>
        new CPAN modules on Fri Sep  8 2006 (Randal Schwartz)
    Re: Non-uniform split anno4000@radom.zrz.tu-berlin.de
    Re: Pattern Matching and skipping <mattjones@hotmail.co.uk>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@augustmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 08 Sep 2006 04:56:39 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: [ANNOUNCE] Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1157691371@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
Maintainer: Jari Aalto A T cante net

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            and XEmacs port

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        http://math.berkeley.edu/~ilya/software/emacs/
        by Ilya Zakharevich

        CPerl is major mode for editing perl files. Also included in
        latest Emacs, but newest version is at Ilya's site. Note that
        the directrory at CPAN is out of date:
        http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/

        Compared to default `perl-mode' that comes with Emacs, this
        one has more features.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr@ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



------------------------------

Date: Fri, 08 Sep 2006 05:11:25 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: beginners question
Message-Id: <1Y6Mg.326$bf5.57@edtnps90>

Alpha wrote:
> Hi guys, n00bs here.
> 
> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes
> after that.
> so $string will become "String 12345 String 67890 ";
> 
> any hints will be appreciated.

$ perl -le'
    $string = "String 12345 String 67890 String whatever here";
    $string =~ s/\D+$//;
    print $string;
'
String 12345 String 67890


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 7 Sep 2006 22:33:05 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: beginners question
Message-Id: <1157693585.095165.235550@h48g2000cwc.googlegroups.com>

Alpha wrote:
> Hi guys, n00bs here.
>
> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes
> after that.
> so $string will become "String 12345 String 67890 ";
>
> any hints will be appreciated.
> 

   $string =~ s/(?!.* String).*//;

Xicheng



------------------------------

Date: Fri, 08 Sep 2006 15:54:44 +1000
From: Alpha <nospam@diespammer.com>
Subject: Re: beginners question
Message-Id: <450105a7$0$790$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Okay guys, there's a bit of misunderstanding in my part here. What I 
really want is to match a string like this:
$str = "whatever Test bla bhlah 123123!!@#!@# Test whoever 123aojiaso 
Test i don't want to see this part in the end";

the result will be "whatever Test bla bhlah 123123!!@#!@# Test whoever 
123aojiaso "

so the regexp will strip off the last "Test" and whatever that comes 
after that, on a string that doesn't have a pattern except that "Test" 
will appear at least once in the document.

If it only appears once, like here
$str = "whatever bla bla bla bla bla Test 123combination of strings and 
!@#!@#",
it will give me
"whatever bla bla bla bla bla";

in weird situation:
$str = "Test whatever 12345";
it will just return empty string
and on $str = "Test Test Test whatever 12345";
it will return "Test Test ".

hope that makes it clear now, and thanks for the help ;)

Regards,
Alpha.


Alpha wrote:
> Hi guys, n00bs here.
> 
> I was playing around with regexp and got stuck with this:
> $string ="String 12345 String 67890 String whatever here";
> basically i want to strip off the last "String" and whatever that comes 
> after that.
> so $string will become "String 12345 String 67890 ";
> 
> any hints will be appreciated.
> 
> Thanks,
> Alpha


------------------------------

Date: Fri, 08 Sep 2006 16:34:39 +1000
From: Alpha <nospam@diespammer.com>
Subject: Re: beginners question
Message-Id: <45010f02$0$776$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Hey, actually this solves my problem.
Could you please explain what you're doing here?
Thanks.

Ala Qumsieh wrote:
> Alpha wrote:
>> Hi guys, n00bs here.
>>
>> I was playing around with regexp and got stuck with this:
>> $string ="String 12345 String 67890 String whatever here";
>> basically i want to strip off the last "String" and whatever that 
>> comes after that.
>> so $string will become "String 12345 String 67890 ";
> 
> I don't think any of the given solutions is really what you're looking 
> for. Perhaps this is?
> 
>     $string =~ s/(.*)String.*/$1/;
> 
> --Ala
> 


------------------------------

Date: 08 Sep 2006 06:49:59 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: beginners question
Message-Id: <slrneg24km.d0.abigail@alexandra.abigail.be>

Alpha (nospam@diespammer.com) wrote on MMMMDCCLVI September MCMXCIII in
<URL:news:450105a7$0$790$5a62ac22@per-qv1-newsreader-01.iinet.net.au>:
--  Okay guys, there's a bit of misunderstanding in my part here. What I 
--  really want is to match a string like this:
--  $str = "whatever Test bla bhlah 123123!!@#!@# Test whoever 123aojiaso 
--  Test i don't want to see this part in the end";
--  
--  the result will be "whatever Test bla bhlah 123123!!@#!@# Test whoever 
--  123aojiaso "
--  
--  so the regexp will strip off the last "Test" and whatever that comes 
--  after that, on a string that doesn't have a pattern except that "Test" 
--  will appear at least once in the document.
--  
--  If it only appears once, like here
--  $str = "whatever bla bla bla bla bla Test 123combination of strings and 
-- !@#!@#",
--  it will give me
--  "whatever bla bla bla bla bla";
--  
--  in weird situation:
--  $str = "Test whatever 12345";
--  it will just return empty string
--  and on $str = "Test Test Test whatever 12345";
--  it will return "Test Test ".
--  
--  hope that makes it clear now, and thanks for the help ;)


Untested:

    s/Test[^T]*(?:T(?!est)[^T]*)*//;


Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


------------------------------

Date: Fri, 08 Sep 2006 09:21:29 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: beginners question
Message-Id: <edr5p3$p9e$1@nntp.fujitsu-siemens.com>

Alpha wrote:
> Hey, actually this solves my problem.
> Could you please explain what you're doing here?
> Thanks.

Please don't top-post!

> Ala Qumsieh wrote:
>=20
>> Alpha wrote:
>>
>>> Hi guys, n00bs here.
>>>
>>> I was playing around with regexp and got stuck with this:
>>> $string =3D"String 12345 String 67890 String whatever here";
>>> basically i want to strip off the last "String" and whatever that=20
>>> comes after that.
>>> so $string will become "String 12345 String 67890 ";
>>
>>
>> I don't think any of the given solutions is really what you're looking=
=20
>> for. Perhaps this is?
>>
>>     $string =3D~ s/(.*)String.*/$1/;

The keyword here is "greedy". Try reading up on Perl's pattern matching=20
and on how patterns can be greedy.

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



------------------------------

Date: Fri, 08 Sep 2006 09:32:32 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: beginners question
Message-Id: <edr6du$tfd$1@nntp.fujitsu-siemens.com>

Alpha wrote:
> Okay guys, there's a bit of misunderstanding in my part here. What I=20
> really want is to match a string like this:
> $str =3D "whatever Test bla bhlah 123123!!@#!@# Test whoever 123aojiaso=
=20
> Test i don't want to see this part in the end";
>=20
> the result will be "whatever Test bla bhlah 123123!!@#!@# Test whoever =

> 123aojiaso "
>=20
> so the regexp will strip off the last "Test" and whatever that comes=20
> after that, on a string that doesn't have a pattern except that "Test" =

> will appear at least once in the document.
>=20
> If it only appears once, like here
> $str =3D "whatever bla bla bla bla bla Test 123combination of strings a=
nd=20
> !@#!@#",
> it will give me
> "whatever bla bla bla bla bla";
>=20
> in weird situation:
> $str =3D "Test whatever 12345";
> it will just return empty string
> and on $str =3D "Test Test Test whatever 12345";
> it will return "Test Test ".
>=20
> hope that makes it clear now, and thanks for the help ;)
>=20
> Regards,
> Alpha.
>=20
>=20
> Alpha wrote:
>=20
>> Hi guys, n00bs here.
>>
>> I was playing around with regexp and got stuck with this:
>> $string =3D"String 12345 String 67890 String whatever here";
>> basically i want to strip off the last "String" and whatever that=20
>> comes after that.
>> so $string will become "String 12345 String 67890 ";
>>
>> any hints will be appreciated.
>>
>> Thanks,
>> Alpha

Again: please don't top-post (but then, you probably haven't read my=20
previous reply ;-)

Since you don't have a fixed word you're after, I suggest you split()=20
the string into (nonblank) words and then step through the resulting=20
array counting the words, remembering where the word was, and then=20
taking a slice of that array and join()ing it back.

untested:

my @words =3D split(' ', $str);
my %wordcount =3D ();
my %lastoccurrence =3D ();
for (my $i =3D 0; $i <=3D $#words; $i++) {
     my $word =3D $words[$i];
     if (isaproperword($word)) {	# e.g. $word =3D~ /^\w+$/
	$wordcount{$word}++;
	$lastoccurrence{$word} =3D $i;
     }
}
my $lastindex =3D @words;
foreach (keys %wordcount) {
     next unless ($wordcount{$_} =3D=3D 1);
     $lastindex =3D $lastoccurrence{$_} if ($lastoccurrence{$_} < $lastin=
dex);
}
$lastindex =3D 1 if $lastindex =3D=3D @words;
$str =3D join(' ', @words[0..$lastindex-1];

HTH,

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



------------------------------

Date: Fri, 8 Sep 2006 04:42:07 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Fri Sep  8 2006
Message-Id: <J59Bq7.1FvA@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.

Apache2-Mogile-Dispatch-0.2
http://search.cpan.org/~sock/Apache2-Mogile-Dispatch-0.2/
An Apache2 MogileFS Dispatcher
----
Apache2-Mogile-Dispatch-0.2.1
http://search.cpan.org/~sock/Apache2-Mogile-Dispatch-0.2.1/
An Apache2 MogileFS Dispatcher
----
Bio-Phylo-0.13
http://search.cpan.org/~rvosa/Bio-Phylo-0.13/
Phylogenetic analysis using perl.
----
Bio-Phylo-0.14
http://search.cpan.org/~rvosa/Bio-Phylo-0.14/
Phylogenetic analysis using perl.
----
Bundle-CIPRES-0.03
http://search.cpan.org/~rvosa/Bundle-CIPRES-0.03/
CPAN Bundle for CIPRES prerequisites
----
Catalyst-Plugin-Authentication-Credential-HTTP-0.06
http://search.cpan.org/~nuffin/Catalyst-Plugin-Authentication-Credential-HTTP-0.06/
HTTP Basic and Digest authentication for Catlayst.
----
Catalyst-Plugin-FormBuilder-1.05
http://search.cpan.org/~nwiger/Catalyst-Plugin-FormBuilder-1.05/
Catalyst FormBuilder Plugin
----
Config-Model-0.602
http://search.cpan.org/~ddumont/Config-Model-0.602/
Model to create configuration validation tool
----
Data-Define-1.01
http://search.cpan.org/~stro/Data-Define-1.01/
Make undef's defined
----
Data-Hierarchy-0.31
http://search.cpan.org/~clkao/Data-Hierarchy-0.31/
Handle data in a hierarchical structure
----
FTN-Address-1.02
http://search.cpan.org/~stro/FTN-Address-1.02/
Process FTN addresses
----
File-Copy-Recursive-0.28
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.28/
Perl extension for recursively copying files and directories
----
Geo-GD-Image-0.02
http://search.cpan.org/~jdiepen/Geo-GD-Image-0.02/
Perl extension to draw Well Known Binary (WKB) blobs directly into a GD::Image
----
Geo-Postcodes-0.21
http://search.cpan.org/~arne/Geo-Postcodes-0.21/
Base class for the Geo::Postcodes::XX modules
----
Geo-Postcodes-DK-0.21
http://search.cpan.org/~arne/Geo-Postcodes-DK-0.21/
Danish postcodes with associated information
----
Geo-Postcodes-NO-0.21
http://search.cpan.org/~arne/Geo-Postcodes-NO-0.21/
Norwegian postcodes with associated information
----
HTML-WikiConverter-Socialtext-0.03
http://search.cpan.org/~synedra/HTML-WikiConverter-Socialtext-0.03/
Convert HTML to Socialtext markup
----
IO-Capture-Extended-0.11
http://search.cpan.org/~jkeenan/IO-Capture-Extended-0.11/
Extend functionality of IO::Capture
----
Log-Dispatch-File-Stamped-0.04
http://search.cpan.org/~cholet/Log-Dispatch-File-Stamped-0.04/
Logging to date/time stamped files
----
Log-Dispatch-File-Stamped-0.05
http://search.cpan.org/~cholet/Log-Dispatch-File-Stamped-0.05/
Logging to date/time stamped files
----
Mail-Address-MobileJp-0.07
http://search.cpan.org/~miyagawa/Mail-Address-MobileJp-0.07/
mobile email address in Japan
----
Module-CoreList-2.08
http://search.cpan.org/~rgarcia/Module-CoreList-2.08/
what modules shipped with versions of perl
----
Net-FeedBurner-0.11
http://search.cpan.org/~sock/Net-FeedBurner-0.11/
The great new Net::FeedBurner!
----
Net-Lite-FTP-0.46
http://search.cpan.org/~eyck/Net-Lite-FTP-0.46/
Perl FTP client with support for TLS
----
Net-Lite-FTP-0.47
http://search.cpan.org/~eyck/Net-Lite-FTP-0.47/
Perl FTP client with support for TLS
----
Net-NBsocket-0.13
http://search.cpan.org/~miker/Net-NBsocket-0.13/
Non-Blocking Sockets
----
Net-Netmask-1.9013
http://search.cpan.org/~muir/Net-Netmask-1.9013/
parse, manipulate and lookup IP network blocks
----
Net-Ping-External-0.12_01
http://search.cpan.org/~chorny/Net-Ping-External-0.12_01/
Cross-platform interface to ICMP "ping" utilities
----
OOPS-0.1005
http://search.cpan.org/~muir/OOPS-0.1005/
Object Oriented Persistent Store
----
POE-Component-IRC-5.01
http://search.cpan.org/~bingos/POE-Component-IRC-5.01/
a fully event-driven IRC client module.
----
Pod-XML-0.97
http://search.cpan.org/~mwilson/Pod-XML-0.97/
Module to convert POD to XML
----
SAP-Rfc-1.48
http://search.cpan.org/~piers/SAP-Rfc-1.48/
SAP RFC - RFC Function calls against an SAP R/3 System
----
Sub-ForceEval-1.00
http://search.cpan.org/~lembark/Sub-ForceEval-1.00/
runtime cluck if a dying subrutine is not eval-ed.
----
Sys-Sig-0.03
http://search.cpan.org/~miker/Sys-Sig-0.03/
return signal constants for this host
----
Test-Chimps-0.07
http://search.cpan.org/~zev/Test-Chimps-0.07/
Collaborative Heterogeneous Infinite Monkey Perfectionification Service
----
Test-Object-0.07
http://search.cpan.org/~adamk/Test-Object-0.07/
Thoroughly testing objects via registered handlers
----
Text-PDF-0.29a
http://search.cpan.org/~mhosken/Text-PDF-0.29a/
Module for manipulating PDF files
----
Text-Restructured-0.003018
http://search.cpan.org/~nodine/Text-Restructured-0.003018/
----
URI-urn-uuid-0.01
http://search.cpan.org/~miyagawa/URI-urn-uuid-0.01/
UUID URN Namespace
----
WWW-Dict-TWMOE-Phrase-0.03
http://search.cpan.org/~gugod/WWW-Dict-TWMOE-Phrase-0.03/
TWMOE Chinese Phrase Dictionary interface.
----
WWW-RobotRules-Memcache-0.1
http://search.cpan.org/~sock/WWW-RobotRules-Memcache-0.1/
Use memcached in conjunction with WWW::RobotRules
----
as-0.02
http://search.cpan.org/~elizabeth/as-0.02/
load OO module under another name
----
as-0.03
http://search.cpan.org/~elizabeth/as-0.03/
load OO module under another name
----
as-0.04
http://search.cpan.org/~elizabeth/as-0.04/
load OO module under another name


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: 8 Sep 2006 09:43:17 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Non-uniform split
Message-Id: <4mcs9lF5jrarU1@news.dfncis.de>

Dark <darkknight0072004@yahoo.com> wrote in comp.lang.perl.misc:
> >
> > Is there any other way apart from split by which i cud achieve this
> > (assuming that there is no single regex to spit on) ?
> >
> > Any possible way (as far as I can loop..since no of lines is huge)
> >
> > Thanks.
> > Greg
> 
> If you really want to use a regex here is something primative that
> might get the job done (fills a hash and prints it - keeping track of
> line numbers and columns). I'd probably just use unpack.
> 
> -I

Hmm...  Your code is not strict-safe and produces a lot of warnings
when those are switched on.  The indentation is random.  When run,
it outputs 60 lines, beginning

    Line 0 column
    a=""
    Line 0 column
    b=""
    Line 0 column
    c=""
    Line 0 column
    d=""
    Line 0 column
    e=""
    Line 1 column
    a=""
    Line 1 column
    ....

Is that what it is supposed to do?

> $data = <<HERE

Semicolon missing after that statement.

> A      B       C          D      E
> d32    ab      ae99       WB     89
> d33    cd      e787       WC     78
> d34    ef                 WD
> d35    gh      ancjd      WT     100
> d36    ij                 WP
> 
> HERE
> ;

Misplaced semicolon.

> @lines = split("\n", $data);
> my %data;

The keys in %data are the values of $counter below, so essentially the
input line numbers.  That kind of data is better kept in an array.  Make
that

    my @data,

> my $counter;
> for ($counter=0;$counter<=$#lines;$counter++) {
> $line = $lines[$counter];
> $_ = $line;

All this data-shuffling is unnecessary.  Replace it with

    for ( split /\n/, $data ) {

> /([0-9\sa-zA-Z]{0,7})([0-9\sa-zA-Z]{0,8})([0-9\sa-zA-Z]{0,11})([0-9\sa-zA-Z]{0,7})([0-9\sa-zA-Z]{0,7})/;

This regex is too big to be placed in the code directly.  Define a regex
variable outside the loop (my $re = qr/.../;) and use $re here:

    /$re/;

I have not checked if the regex does indeed match what it needs to,
I'm assuming it does.  However, it captures trailing blanks with each
field.  In a complete solution these should be dropped.

> if ($1) {

What if $1 happens to contain a false boolean value?  Check the entire
match for success, not one haphazard match variable.

>         $data{$counter}{'a'} = $1;
>         $data{$counter}{'b'} = $2;
>         $data{$counter}{'c'} = $3;
>         $data{$counter}{'d'} = $4;
>         $data{$counter}{'e'} = $5;

Since @data is an array now, this must be written differently:

    push @data, { a => $1, b => $2, c => $3, d => $4, e => $5};

I'd write the entire loop body like this:

    if ( my @cols = /$re/ ) {
        push @data, { map { $_ => shift @cols } qw( a b c d e);
    } else {
        warn "invalid data";
    }

> }
> }

The print loop below is also more roundabout than it has to be.

> #Print out the data in the hash
> for ($counter=0;$counter<=$#lines;$counter++) {
>         my @cols;
>      ($cols[0], $cols[1], $cols[2], $cols[3], $cols[4]) =
> ('a','b','c','d','e');
>      for ($incount=0;$incount<=$#cols;$incount++) {
>                 print "Line $counter column
> $cols[$incount]=\"$data{$counter}{$cols[$incount]}\"\n";
>      }
>      
> }

That amounts to a re-write along these lines:

    $data = <<HERE;
    A      B       C          D      E
    d32    ab      ae99       WB     89
    d33    cd      e787       WC     78
    d34    ef                 WD
    d35    gh      ancjd      WT     100
    d36    ij                 WP
    HERE

    my $fc = '[0-9\sa-zA-Z]'; # a field character
    my $re = qr/($fc{0,7})($fc{0,8})($fc{0,11})($fc{0,7})($fc{0,7})/;

    my @recs;
    for ( split /\n/, $data) {
        if ( my @cols = /$re/ ) {
            s/ +$// for @cols; # trim trailing blanks
            @{ $recs[ @recs]}{ 'a' .. 'e'} = @cols;
        }
    }

    for my $rec ( @recs ) {
        print join( ', ', map "$_ => $rec->{ $_}", sort keys %$rec), "\n";
    }

Anno


------------------------------

Date: 8 Sep 2006 00:48:43 -0700
From: "MattJ83" <mattjones@hotmail.co.uk>
Subject: Re: Pattern Matching and skipping
Message-Id: <1157701723.780881.319030@e3g2000cwe.googlegroups.com>


Tad McClellan schrieb:

> MattJ83 <mattjones@hotmail.co.uk> wrote:
>
> > I do appreciate your help in guiding me through this code - so far i've
> > just had a book and been told to right a script!
>
>
> Writing a script is not too difficult.
> 
> Righting a script is more difficult.
> 
sorry - yes, write.... !



------------------------------

Date: 08 Sep 2006 07:22:44 GMT
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.6 $)
Message-Id: <45011a44$0$47253$ae4e5890@news.nationwide.net>

Outline
   Before posting to comp.lang.perl.misc
      Must
       - Check the Perl Frequently Asked Questions (FAQ)
       - Check the other standard Perl docs (*.pod)
      Really Really Should
       - Lurk for a while before posting
       - Search a Usenet archive
      If You Like
       - Check Other Resources
   Posting to comp.lang.perl.misc
      Is there a better place to ask your question?
       - Question should be about Perl, not about the application area
      How to participate (post) in the clpmisc community
       - Carefully choose the contents of your Subject header
       - Use an effective followup style
       - Speak Perl rather than English, when possible
       - Ask perl to help you
       - Do not re-type Perl code
       - Provide enough information
       - Do not provide too much information
       - Do not post binaries, HTML, or MIME
      Social faux pas to avoid
       - Asking a Frequently Asked Question
       - Asking a question easily answered by a cursory doc search
       - Asking for emailed answers
       - Beware of saying "doesn't work"
       - Sending a "stealth" Cc copy
      Be extra cautious when you get upset
       - Count to ten before composing a followup when you are upset
       - Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------

Posting Guidelines for comp.lang.perl.misc ($Revision: 1.6 $)
    This newsgroup, commonly called clpmisc, is a technical newsgroup
    intended to be used for discussion of Perl related issues (except job
    postings), whether it be comments or questions.

    As you would expect, clpmisc discussions are usually very technical in
    nature and there are conventions for conduct in technical newsgroups
    going somewhat beyond those in non-technical newsgroups.

    The article at:

        http://www.catb.org/~esr/faqs/smart-questions.html

    describes how to get answers from technical people in general.

    This article describes things that you should, and should not, do to
    increase your chances of getting an answer to your Perl question. It is
    available in POD, HTML and plain text formats at:

     http://www.augustmail.com/~tadmc/clpmisc.shtml

    For more information about netiquette in general, see the "Netiquette
    Guidelines" at:

     http://andrew2.andrew.cmu.edu/rfc/rfc1855.html

    A note to newsgroup "regulars":

       Do not use these guidelines as a "license to flame" or other
       meanness. It is possible that a poster is unaware of things
       discussed here.  Give them the benefit of the doubt, and just
       help them learn how to post, rather than assume 

    A note about technical terms used here:

       In this document, we use words like "must" and "should" as
       they're used in technical conversation (such as you will
       encounter in this newsgroup). When we say that you *must* do
       something, we mean that if you don't do that something, then
       it's unlikely that you will benefit much from this group.
       We're not bossing you around; we're making the point without
       lots of words.

    Do *NOT* send email to the maintainer of these guidelines. It will be
    discarded unread. The guidelines belong to the newsgroup so all
    discussion should appear in the newsgroup. I am just the secretary that
    writes down the consensus of the group.

Before posting to comp.lang.perl.misc
  Must
    This section describes things that you *must* do before posting to
    clpmisc, in order to maximize your chances of getting meaningful replies
    to your inquiry and to avoid getting flamed for being lazy and trying to
    have others do your work.

    The perl distribution includes documentation that is copied to your hard
    drive when you install perl. Also installed is a program for looking
    things up in that (and other) documentation named 'perldoc'.

    You should either find out where the docs got installed on your system,
    or use perldoc to find them for you. Type "perldoc perldoc" to learn how
    to use perldoc itself. Type "perldoc perl" to start reading Perl's
    standard documentation.

    Check the Perl Frequently Asked Questions (FAQ)
        Checking the FAQ before posting is required in Big 8 newsgroups in
        general, there is nothing clpmisc-specific about this requirement.
        You are expected to do this in nearly all newsgroups.

        You can use the "-q" switch with perldoc to do a word search of the
        questions in the Perl FAQs.

    Check the other standard Perl docs (*.pod)
        The perl distribution comes with much more documentation than is
        available for most other newsgroups, so in clpmisc you should also
        see if you can find an answer in the other (non-FAQ) standard docs
        before posting.

    It is *not* required, or even expected, that you actually *read* all of
    Perl's standard docs, only that you spend a few minutes searching them
    before posting.

    Try doing a word-search in the standard docs for some words/phrases
    taken from your problem statement or from your very carefully worded
    "Subject:" header.

  Really Really Should
    This section describes things that you *really should* do before posting
    to clpmisc.

    Lurk for a while before posting
        This is very important and expected in all newsgroups. Lurking means
        to monitor a newsgroup for a period to become familiar with local
        customs. Each newsgroup has specific customs and rituals. Knowing
        these before you participate will help avoid embarrassing social
        situations. Consider yourself to be a foreigner at first!

    Search a Usenet archive
        There are tens of thousands of Perl programmers. It is very likely
        that your question has already been asked (and answered). See if you
        can find where it has already been answered.

        One such searchable archive is:

         http://groups.google.com/advanced_group_search

  If You Like
    This section describes things that you *can* do before posting to
    clpmisc.

    Check Other Resources
        You may want to check in books or on web sites to see if you can
        find the answer to your question.

        But you need to consider the source of such information: there are a
        lot of very poor Perl books and web sites, and several good ones
        too, of course.

Posting to comp.lang.perl.misc
    There can be 200 messages in clpmisc in a single day. Nobody is going to
    read every article. They must decide somehow which articles they are
    going to read, and which they will skip.

    Your post is in competition with 199 other posts. You need to "win"
    before a person who can help you will even read your question.

    These sections describe how you can help keep your article from being
    one of the "skipped" ones.

  Is there a better place to ask your question?
    Question should be about Perl, not about the application area
        It can be difficult to separate out where your problem really is,
        but you should make a conscious effort to post to the most
        applicable newsgroup. That is, after all, where you are the most
        likely to find the people who know how to answer your question.

        Being able to "partition" a problem is an essential skill for
        effectively troubleshooting programming problems. If you don't get
        that right, you end up looking for answers in the wrong places.

        It should be understood that you may not know that the root of your
        problem is not Perl-related (the two most frequent ones are CGI and
        Operating System related), so off-topic postings will happen from
        time to time. Be gracious when someone helps you find a better place
        to ask your question by pointing you to a more applicable newsgroup.

  How to participate (post) in the clpmisc community
    Carefully choose the contents of your Subject header
        You have 40 precious characters of Subject to win out and be one of
        the posts that gets read. Don't waste them. Take care while
        composing them, they are the key that opens the door to getting an
        answer.

        Spend them indicating what aspect of Perl others will find if they
        should decide to read your article.

        Do not spend them indicating "experience level" (guru, newbie...).

        Do not spend them pleading (please read, urgent, help!...).

        Do not spend them on non-Subjects (Perl question, one-word
        Subject...)

        For more information on choosing a Subject see "Choosing Good
        Subject Lines":

         http://www.cpan.org/authors/id/D/DM/DMR/subjects.post

        Part of the beauty of newsgroup dynamics, is that you can contribute
        to the community with your very first post! If your choice of
        Subject leads a fellow Perler to find the thread you are starting,
        then even asking a question helps us all.

    Use an effective followup style
        When composing a followup, quote only enough text to establish the
        context for the comments that you will add. Always indicate who
        wrote the quoted material. Never quote an entire article. Never
        quote a .signature (unless that is what you are commenting on).

        Intersperse your comments *following* each section of quoted text to
        which they relate. Unappreciated followup styles are referred to as
        "top-posting", "Jeopardy" (because the answer comes before the
        question), or "TOFU" (Text Over, Fullquote Under).

        Reversing the chronology of the dialog makes it much harder to
        understand (some folks won't even read it if written in that style).
        For more information on quoting style, see:

         http://web.presby.edu/~nnqadmin/nnq/nquote.html

    Speak Perl rather than English, when possible
        Perl is much more precise than natural language. Saying it in Perl
        instead will avoid misunderstanding your question or problem.

        Do not say: I have variable with "foo\tbar" in it.

        Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
        or I have $var = <DATA> (and show the data line).

    Ask perl to help you
        You can ask perl itself to help you find common programming mistakes
        by doing two things: enable warnings (perldoc warnings) and enable
        "strict"ures (perldoc strict).

        You should not bother the hundreds/thousands of readers of the
        newsgroup without first seeing if a machine can help you find your
        problem. It is demeaning to be asked to do the work of a machine. It
        will annoy the readers of your article.

        You can look up any of the messages that perl might issue to find
        out what the message means and how to resolve the potential mistake
        (perldoc perldiag). If you would like perl to look them up for you,
        you can put "use diagnostics;" near the top of your program.

    Do not re-type Perl code
        Use copy/paste or your editor's "import" function rather than
        attempting to type in your code. If you make a typo you will get
        followups about your typos instead of about the question you are
        trying to get answered.

    Provide enough information
        If you do the things in this item, you will have an Extremely Good
        chance of getting people to try and help you with your problem!
        These features are a really big bonus toward your question winning
        out over all of the other posts that you are competing with.

        First make a short (less than 20-30 lines) and *complete* program
        that illustrates the problem you are having. People should be able
        to run your program by copy/pasting the code from your article. (You
        will find that doing this step very often reveals your problem
        directly. Leading to an answer much more quickly and reliably than
        posting to Usenet.)

        Describe *precisely* the input to your program. Also provide example
        input data for your program. If you need to show file input, use the
        __DATA__ token (perldata.pod) to provide the file contents inside of
        your Perl program.

        Show the output (including the verbatim text of any messages) of
        your program.

        Describe how you want the output to be different from what you are
        getting.

        If you have no idea at all of how to code up your situation, be sure
        to at least describe the 2 things that you *do* know: input and
        desired output.

    Do not provide too much information
        Do not just post your entire program for debugging. Most especially
        do not post someone *else's* entire program.

    Do not post binaries, HTML, or MIME
        clpmisc is a text only newsgroup. If you have images or binaries
        that explain your question, put them in a publically accessible
        place (like a Web server) and provide a pointer to that location. If
        you include code, cut and paste it directly in the message body.
        Don't attach anything to the message. Don't post vcards or HTML.
        Many people (and even some Usenet servers) will automatically filter
        out such messages. Many people will not be able to easily read your
        post. Plain text is something everyone can read.

  Social faux pas to avoid
    The first two below are symptoms of lots of FAQ asking here in clpmisc.
    It happens so often that folks will assume that it is happening yet
    again. If you have looked but not found, or found but didn't understand
    the docs, say so in your article.

    Asking a Frequently Asked Question
        It should be understood that you may have missed the applicable FAQ
        when you checked, which is not a big deal. But if the Frequently
        Asked Question is worded similar to your question, folks will assume
        that you did not look at all. Don't become indignant at pointers to
        the FAQ, particularly if it solves your problem.

    Asking a question easily answered by a cursory doc search
        If folks think you have not even tried the obvious step of reading
        the docs applicable to your problem, they are likely to become
        annoyed.

        If you are flamed for not checking when you *did* check, then just
        shrug it off (and take the answer that you got).

    Asking for emailed answers
        Emailed answers benefit one person. Posted answers benefit the
        entire community. If folks can take the time to answer your
        question, then you can take the time to go get the answer in the
        same place where you asked the question.

        It is OK to ask for a *copy* of the answer to be emailed, but many
        will ignore such requests anyway. If you munge your address, you
        should never expect (or ask) to get email in response to a Usenet
        post.

        Ask the question here, get the answer here (maybe).

    Beware of saying "doesn't work"
        This is a "red flag" phrase. If you find yourself writing that,
        pause and see if you can't describe what is not working without
        saying "doesn't work". That is, describe how it is not what you
        want.

    Sending a "stealth" Cc copy
        A "stealth Cc" is when you both email and post a reply without
        indicating *in the body* that you are doing so.

  Be extra cautious when you get upset
    Count to ten before composing a followup when you are upset
        This is recommended in all Usenet newsgroups. Here in clpmisc, most
        flaming sub-threads are not about any feature of Perl at all! They
        are most often for what was seen as a breach of netiquette. If you
        have lurked for a bit, then you will know what is expected and won't
        make such posts in the first place.

        But if you get upset, wait a while before writing your followup. I
        recommend waiting at least 30 minutes.

    Count to ten after composing and before posting when you are upset
        After you have written your followup, wait *another* 30 minutes
        before committing yourself by posting it. You cannot take it back
        once it has been said.

AUTHOR
    Tad McClellan <tadmc@augustmail.com> and many others on the
    comp.lang.perl.misc newsgroup.



------------------------------

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 V10 Issue 9702
***************************************


home help back first fref pref prev next nref lref last post