[22624] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4845 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 15 00:05:57 2003

Date: Mon, 14 Apr 2003 21:05:09 -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           Mon, 14 Apr 2003     Volume: 10 Number: 4845

Today's topics:
    Re: avoid using extra variable <ericosman@rcn.com>
        Beginners qn about while loops/regex (Matt T)
    Re: Beginners qn about while loops/regex <jkeen@concentric.net>
    Re: Beginners qn about while loops/regex <wksmith@optonline.net>
        Does Perl have a line length limit (johnston)
    Re: Does Perl have a line length limit <michael.p.broida@boeing.com>
    Re: error when reading file what is wrong <uri@stemsystems.com>
    Re: error when reading file what is wrong <michael.p.broida@boeing.com>
    Re: executing perl script (bhat)
        GD::Graph-How to display string instead of values on ax (Valerie VANLERBERGHE)
        GD::Graph-How to display string instead of values on ax (Valerie VANLERBERGHE)
    Re: GD::Graph-How to display string instead of values o <mgjv@tradingpost.com.au>
    Re: Handling negative exitcodes using system() <krahnj@acm.org>
    Re: How to do a regexp to find #'s? <michael.p.broida@boeing.com>
    Re: How to do a regexp to find #'s? (Sam Holden)
    Re: How to do a regexp to find #'s? (Tad McClellan)
    Re: Method inheritance? <goldbb2@earthlink.net>
    Re: newline split (Jay Tilton)
        Perlmonks Down? (Artist)
    Re: regular expression substitution and perl -p -i -e <dfox@ia.net>
    Re: regular expression substitution and perl -p -i -e <jaco2001uk@nospamntlworld.com>
    Re: Shortcut <jurgenex@hotmail.com>
        Specific Regex Question (Cameron)
    Re: suggestions for perl upgrade <GPatnude@adelphia.net>
    Re: To extract a portion of a text file <bwalton@rochester.rr.com>
        Tp process a text file.... (John Smith)
    Re: Tp process a text file.... <wksmith@optonline.net>
    Re: What is wrong? <mail@annuna.com>
    Re: Why do I get an error More code <mail@annuna.com>
    Re: Why do I get an error More code <mgjv@tradingpost.com.au>
    Re: Why do I get an error <mail@annuna.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 14 Apr 2003 22:46:59 -0400
From: Eric Osman <ericosman@rcn.com>
Subject: Re: avoid using extra variable
Message-Id: <3E9B72A3.40100@rcn.com>



Well, Abigail's solution is the sort of thing I was looking for,
because it manages to print the value of the expression without
having to end the quoted string and then restart it, which Richard
and Jue's solutions require.

/Eric



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

Date: 14 Apr 2003 19:26:54 -0700
From: mctrewin@ihug.com.au (Matt T)
Subject: Beginners qn about while loops/regex
Message-Id: <5e41989.0304141826.3a62d48a@posting.google.com>

Hi all,

I have a script that while-loops through each line of a file then
uses another while-loop to run through each word in the line using
a regex to match the words. I would like to know if it is possible
to get the index of the start of the word that I matched? I currently
have a solution which is incorrect. My code is roughly:

while (<INPUTFILE>) {
    $line = $_;
    while ($line =~ /(\w+)/g) {
        # I would like to get the index of the word I matched here!
        # Process the word
    }
}

I tried using the index function, but that will only match the first 
occurance of the word in $line. Any suggestions would be much appreciated.

Matt.


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

Date: 15 Apr 2003 02:50:32 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Beginners qn about while loops/regex
Message-Id: <b7fs1o$68j@dispatch.concentric.net>


"Matt T" <mctrewin@ihug.com.au> wrote in message
news:5e41989.0304141826.3a62d48a@posting.google.com...
> Hi all,
>
> I have a script that while-loops through each line of a file then
> uses another while-loop to run through each word in the line using
> a regex to match the words. I would like to know if it is possible
> to get the index of the start of the word that I matched? I currently
> have a solution which is incorrect. My code is roughly:
>
> while (<INPUTFILE>) {
>     $line = $_;
>     while ($line =~ /(\w+)/g) {
>         # I would like to get the index of the word I matched here!
>         # Process the word
>     }
> }
>
> I tried using the index function, but that will only match the first
> occurance of the word in $line. Any suggestions would be much appreciated.
>
I'm not sure what your ultimate objective is.  However, if you do indeed
wish to do something with every "word" in a line, and if *your* definition
of a word matches Perl's (\w is shortcut for [A-Za-z0-9_]), then you could
dispense with the regex and simply split the line on non-word characters (my
@words = split /\W+/, $line;).  Granted, that wouldn't give you the index of
each word, but it might be more useful in the long run.  HTH!

Jim Keenan




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

Date: Tue, 15 Apr 2003 03:11:55 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Beginners qn about while loops/regex
Message-Id: <%LKma.73584$Xd1.25549553@news4.srv.hcvlny.cv.net>


"Matt T" <mctrewin@ihug.com.au> wrote in message
news:5e41989.0304141826.3a62d48a@posting.google.com...
> Hi all,
>
> I have a script that while-loops through each line of a file then
> uses another while-loop to run through each word in the line using
> a regex to match the words. I would like to know if it is possible
> to get the index of the start of the word that I matched? I currently
> have a solution which is incorrect. My code is roughly:
>
> while (<INPUTFILE>) {
>     $line = $_;
>     while ($line =~ /(\w+)/g) {
>         # I would like to get the index of the word I matched here!
>         # Process the word
>     }
> }
>
> I tried using the index function, but that will only match the first
> occurance of the word in $line. Any suggestions would be much
appreciated.
>

perldoc -f pos

Bill




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

Date: 14 Apr 2003 17:48:25 -0500
From: johnston@thot.com (johnston)
Subject: Does Perl have a line length limit
Message-Id: <3e9b3a11$0$3121$45beb828@newscene.com>

I have a file with very long lines (30,000 comma separated values per line) 
but just a few of them

i want to put each line into a separate file

i use the following

perl -ne 'print if $.==1' p.txt > p1.txt  

perl -ne 'print if $.==2' p.txt > p2.txt  

p is 6,000,000 bytes in size but both p1 and p2.txt files end up exactly the 
same size 20,402 bytes.  is there a limit to the size of line?


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

Date: Tue, 15 Apr 2003 00:08:23 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Does Perl have a line length limit
Message-Id: <3E9B4D77.575C5E70@boeing.com>

johnston wrote:
> 
> I have a file with very long lines (30,000 comma separated values per line)
> but just a few of them
> 
> i want to put each line into a separate file
> 
> i use the following
> 
> perl -ne 'print if $.==1' p.txt > p1.txt
> 
> perl -ne 'print if $.==2' p.txt > p2.txt
> 
> p is 6,000,000 bytes in size but both p1 and p2.txt files end up exactly the
> same size 20,402 bytes.  is there a limit to the size of line?

	$. is the INPUT_LINE_NUMBER.  It looks to me like you're saying
	is effectively:

		print line number 1 to p1.txt
		print line number 2 to p2.txt

	Look in p1.txt and p2.txt and p.txt and see if that looks like
	what is happening:
	    Is there only one line in p1.txt?
	        Is it the same as the first line of p.txt?
	    Is there only one line in p2.txt?
	        Is it the same asa the second line of p.txt?

		Mike


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

Date: Mon, 14 Apr 2003 22:14:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: error when reading file what is wrong
Message-Id: <x7llyc9175.fsf@mail.sysarch.com>

>>>>> "j" == julio  <julio@hot.com> writes:

  j>    while() {

what does that do? does it read in any data? how could it?

  j>         s/FORD/xxxx/g

  j> Use of uninitialized value in substitution (s///) at p.sh line 19.

where is the data that the s/// works on?

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: Tue, 15 Apr 2003 00:03:14 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: error when reading file what is wrong
Message-Id: <3E9B4C42.9EA60093@boeing.com>

julio wrote:
> 
> running on Sun unix on Sun server
> 
> i have following code
> 
> #!/usr/local/bin/perl -w
> #
> #---------------------------------------------------------------#
> #  A program to read an #
> #---------------------------------------------------------------#
> 
>    $logFile = "tag.txt";
> 
>    open (LOGFILE,"$logFile") || die "  Error opening log file $logFile.\n";
> 
>    while() {
> 
>          #----------------------------------------------#
>          #  condense one or more whitespace character   #
>          #  to one single space                         #
>          #----------------------------------------------#
> 
>         s/FORD/xxxx/g
>          }
> 
>    close (LOGFILE);
> 
> tag.txt line looks like
> 
> 13 CRAWFORD 38TR82       MW
> 13 CRAWFORD 38TR82    45 MW
> 13 CRAWFORD 38TR82    CT MW
> 13 CRAWFORD 38TR83       MW
> 13 CRAWFORD 38TR83    45 MW
> 13 CRAWFORD 38TR83    CT MW
> 13 CRAWFORD 38TR84       MW
> 13 CRAWFORD 38TR84    45 MW
> 
> i get error
> 
> Use of uninitialized value in substitution (s///) at p.sh line 19.
> 
> what is wrong

	The s/// construct you're using wants to modify
	the contents of "$_".  But nothing has been put
	into $_ yet.  You need to add something to read
	data from the file you just opened.

		Mike


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

Date: 14 Apr 2003 19:56:34 -0700
From: rnbhat89@yahoo.com (bhat)
Subject: Re: executing perl script
Message-Id: <4f49dc09.0304141856.6a1b89b7@posting.google.com>

Hello,
  Finally was able to execute the script by using another constructor.
my $mgr     = new Mail::Box::Manager;
$mgr->registerType(pop3 => 'Mail::Box::POP3');
my $folder = $mgr->open("pop3box",
                access => 'rw',
                type => 'pop3',
                authenticate => 'LOGIN',
                username => 'abc',
                password => 'abc',
                server_name => 'mail.abc.net',
                server_port => 110);

 I am now able to find the value in the $folder and my scripts run
when i call them from my browser. The above works but still cannot
find what is the difference between my previous constructor and this
constructor except the word pop3box.

  Thanks for all those who helped me to solve those queries. 
Regards,
Roopa






rook_5150@yahoo.com (Bryan Castillo) wrote in message news:<1bff1830.0304141215.5c442aff@posting.google.com>...
> rnbhat89@yahoo.com (bhat) wrote in message news:<4f49dc09.0304120109.2bcb01da@posting.google.com>...
> > Hello,
> >  I am able to execute the below script from the command prompt.
> > However when i try to run through internet explorer the script doesn't
> > work as intended. The variable $folder in the script below now has
> > null value. Seems like it doesn't execute any command after the
> > statement my $msg = $folder->message(0);. I don't see any error
> > messages. Any clues to solve this problem would be appriciated.
> > Regards,
> > Roopa
> > 
> 
> Have you tried?
> 
> use CGI;
> use CGI::Carp qw{fatalsToBrowser};
> 
> Make sure you put these before the use Mail::X
> 
> That should catch the case where the modules aren't installed
> properly for the web server.
> 
> > 
> > 
> > #!/usr/bin/perl --
> > 
> >   use Mail::Box;
> >   use Mail::Box::POP3;
> >   use Mail::Box::Manager;
> >   use Mail::Message::Body;
> >   use Mail::Message;
> > 
> >  print "Content-type: text/html\n\n";
> 
> If you print something here, will it show up on your browser?
> 
> >  my $mgr     = new Mail::Box::Manager;
> >  my $folder = $mgr->open(type => "pop3", username => "roopa", password
> > => "bhat", server_name => "mail.xxxx.net");
> >  #---i am getting null value in the folder dirctory. 
> 
> If you print something here, will it show up on your browser?
> How do you know the values are null, unless you are able to print something?
> 
> >  my $msg = $folder->message(0);
> >  my $head = $msg->head;
> >  my $body = $msg->body;
> >  #--all the values remain null and even the print statemnt doesn't
> > print anything the below statement.
> >  print "the header is $head\n";
> > #--for the above diagonistic print statement i am expecting to see on
> > the screen "the header is " but i don't even see "the header is "-
> >  
> 
> This is probably because your script died, failed to compile, etc......
> 
> >  $folder->close;


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

Date: 14 Apr 2003 17:56:53 -0700
From: valerie_vanlerberghe@yahoo.fr (Valerie VANLERBERGHE)
Subject: GD::Graph-How to display string instead of values on axis?
Message-Id: <609f743a.0304141310.78782795@posting.google.com>

Is there a way to display string instead of values on y-axis??
I mean, I'd like to display "OK" instead of 1, "Warnings" instead of
value 2, "KO"instead of value 3...on the axis
I tried to use y_number_format as explained on GDGraph page on
CPAN...but I couldn't...I didn't understand how it works...
Could anybody help??

Thanks so much...

Valérie VANLERBERGHE


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

Date: 14 Apr 2003 17:56:57 -0700
From: valerie_vanlerberghe@yahoo.fr (Valerie VANLERBERGHE)
Subject: GD::Graph-How to display string instead of values on axis?
Message-Id: <609f743a.0304141310.7cce7f98@posting.google.com>

Is there a way to display string instead of values on y-axis??
I mean, I'd like to display "OK" instead of 1, "Warnings" instead of
value 2, "KO"instead of value 3...on the axis
I tried to use y_number_format as explained on GDGraph page on
CPAN...but I couldn't...I didn't understand how it works...
Could anybody help??

Thanks so much...

Valérie VANLERBERGHE


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

Date: Tue, 15 Apr 2003 01:05:34 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: GD::Graph-How to display string instead of values on axis?
Message-Id: <slrnb9mmmu.4ba.mgjv@verbruggen.comdyn.com.au>

On 14 Apr 2003 17:56:53 -0700,
	Valerie VANLERBERGHE <valerie_vanlerberghe@yahoo.fr> wrote:
> Is there a way to display string instead of values on y-axis??
> I mean, I'd like to display "OK" instead of 1, "Warnings" instead of
> value 2, "KO"instead of value 3...on the axis
> I tried to use y_number_format as explained on GDGraph page on
> CPAN...but I couldn't...I didn't understand how it works...

Something like (untested):

sub myformat
{
    my $val = shift;
    my @values = qw/OK Warnings KO/;
    return $values[$val - 1] || "ILLEGAL VALUE";
}


# create a GD::Graph object with the name $my_graph
# Then set the formatter:

$my_graph->set( y_number_format => \&myformat );

# Then do the plotting

Martien
-- 
                        | 
Martien Verbruggen      | If at first you don't succeed, destroy all
Trading Post Australia  | evidence that you tried.
                        | 


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

Date: Tue, 15 Apr 2003 00:17:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Handling negative exitcodes using system()
Message-Id: <3E9B4F80.7D05D861@acm.org>

Tom Gevaert wrote:
> 
> "John W. Krahn" <krahnj@acm.org> wrote in message news:<3E949E3A.24B5409D@acm.org>...
> > Tom Gevaert wrote:
> > >
> > > Can anyone tell me how I can catch a negative exitcode when using the
> > > system() function? I use the following commands to execute the
> > > "external" command and to retrieve its exitcode:
> > >
> > >          system (@args)==0 or $exit_value=$?;
> > >          $exit_value = $exit_value >> 8;
> > >
> > > If I have a positive exitcode this works OK. My problem now is that
> > > the external program only delivers negative exitcodes in case of a
> > > problem.
> >
> >           $exit_value = unpack 'c', pack 'C', $exit_value >> 8;
> >
> Thanks for the help, I have tried to do it like this but I still got a
> problem catching the correct exit code. The problem is that I always
> get exit code -1 if the program generates a negative code. This means
> -6 becomes -1 and of course this means that I don't get the correct
> exitcode.

It works for me.

$ perl -le'
system( q[perl -e"exit -6"] );
$exit = $?;
$exit = unpack "c", pack "C", $exit >> 8;
print $exit;
'
-6



John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 14 Apr 2003 23:59:16 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: How to do a regexp to find #'s?
Message-Id: <3E9B4B54.198DD5AD@boeing.com>

Abigail wrote:
> 
> Michael P. Broida (michael.p.broida@boeing.com) wrote on MMMDXIII
> September MCMXCIII in <URL:news:3E9B075C.C57117AB@boeing.com>:
> ||  Jeff Snoxell wrote:
> || >
> || > Hi,
> || >
> || > I want to parse lines of text and remove any comments from them. Can't seem
> || > to get my regexp to work. I'm currently trying to work with this:
> || >
> || > $value =~ s/#+.*$//;
> || >
> || > But its not working, I assume because the interperter thinks #+.*$//; is a
> || > comment itself... so I tried:
> || >
> || > $value =~ s/\#+.*$//;
> || >
> || > And it doesn't like that either.
> ||
> ||      That second one works for me, BUT...   You have to worry
> ||      about HOW you got the # into the $value variable in the
> ||      first place.  If you did it via an assign like:
> ||
> ||              $value = "abc#def";
> ||
> ||      I don't think that will work; the # ends the line.  (I think.)
> 
> You think. How much trouble would it have taken to actually try it?
> 
> Abigail
> --
> You thought wrong.

	I've noticed your answers on the newsgroup today have been
	particularly UNhelpful, just sniping at the other posters.
	Do you have anything useful to offer here, or are you just
	trolling?

	I pointed out a way that works.  From that, the OP knows it
	can be done and can work it out.

		Mike


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

Date: 15 Apr 2003 02:14:09 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: How to do a regexp to find #'s?
Message-Id: <slrnb9mqnh.cuo.sholden@flexal.cs.usyd.edu.au>

On Mon, 14 Apr 2003 23:59:16 GMT,
	Michael P. Broida <michael.p.broida@boeing.com> wrote:
> Abigail wrote:
>> 
>> Michael P. Broida (michael.p.broida@boeing.com) wrote on MMMDXIII
>> September MCMXCIII in <URL:news:3E9B075C.C57117AB@boeing.com>:
>> ||  Jeff Snoxell wrote:
>> || >
>> || > Hi,
>> || >
>> || > I want to parse lines of text and remove any comments from them. Can't seem
>> || > to get my regexp to work. I'm currently trying to work with this:
>> || >
>> || > $value =~ s/#+.*$//;
>> || >
>> || > But its not working, I assume because the interperter thinks #+.*$//; is a
>> || > comment itself... so I tried:
>> || >
>> || > $value =~ s/\#+.*$//;
>> || >
>> || > And it doesn't like that either.
>> ||
>> ||      That second one works for me, BUT...   You have to worry
>> ||      about HOW you got the # into the $value variable in the
>> ||      first place.  If you did it via an assign like:
>> ||
>> ||              $value = "abc#def";
>> ||
>> ||      I don't think that will work; the # ends the line.  (I think.)
>> 
>> You think. How much trouble would it have taken to actually try it?
>> 
>> Abigail
>> --
>> You thought wrong.
> 
> 	I've noticed your answers on the newsgroup today have been
> 	particularly UNhelpful, just sniping at the other posters.
> 	Do you have anything useful to offer here, or are you just
> 	trolling?

You stated something (with an 'i think' excuse) that is obviously false, and
would have taken you approximately 2.5 seconds to test. You did this in an
archived medium that is propogated throughout the world. So that people
will read it and possibly believe it to be a true and hence write buggy and
concoluted code, in order to avoid something which isn't a problem.

Somebody *has* to correct it, so that people stumbling across it will also
stumble across the fact that it is misinformation.

Abigail did that. And gave a little advice that spending a couple of seconds
checking something before posting and having thousands of people all over the
world read it would be wise.

> 	I pointed out a way that works.  From that, the OP knows it
> 	can be done and can work it out.

All you said was 'it works for me' to something the poster had said they
tried. WHich obviously means the poster is doing something else wrong. You
then compounded by the problem by reinforcing their mistaken theory that the
# might start a comment in a quoted expression.

I know which of you and Abigail I consider 'UNhelpful'.

*plonk*

-- 
Sam Holden



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

Date: Mon, 14 Apr 2003 22:13:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to do a regexp to find #'s?
Message-Id: <slrnb9mu6d.jcl.tadmc@magna.augustmail.com>

Michael P. Broida <michael.p.broida@boeing.com> wrote:
> Abigail wrote:
>> Michael P. Broida (michael.p.broida@boeing.com) wrote on MMMDXIII
>> September MCMXCIII in <URL:news:3E9B075C.C57117AB@boeing.com>:
>> ||  Jeff Snoxell wrote:

>> || > $value =~ s/\#+.*$//;

>> ||      That second one works for me, BUT...   You have to worry
>> ||      about HOW you got the # into the $value variable in the
>> ||      first place.  If you did it via an assign like:
>> ||
>> ||              $value = "abc#def";
>> ||
>> ||      I don't think that will work; the # ends the line.  (I think.)
>> 
>> You think. How much trouble would it have taken to actually try it?


Note that rather than spend the 20 seconds it would take to verify
your thinking, you lead the OP down an unproductive path.


>> You thought wrong.
> 
> 	I've noticed your answers on the newsgroup today have been
> 	particularly UNhelpful, 


I've noticed the same thing about _your_ answer. Throwing a
red herring into the mix is unhelpful. It draws the OP
away from whatever his real problem is, which does not have
anything to do with the # sign in the pattern shown above.

Pointing out that you are not thinking correctly _is_ helpful,
allowing you to persist in your misconceptions is unhelpful.

Abigail was helped by clearing up a misconception.

You where unhelpful by offering wild ass guesses that could have
been tested in a few seconds.


>       just sniping at the other posters.


Just leading other posters on a wild goose chase is preferrable?


> 	Do you have anything useful to offer here, or are you just
> 	trolling?


Abigail knows what she is talking about.

You don't. So long.

*plonk*


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 14 Apr 2003 19:36:38 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Method inheritance?
Message-Id: <3E9B4606.A7692A69@earthlink.net>

Matija Papec wrote:
> 
> X-Ftn-To: Benjamin Goldberg
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> >> ---[test.pl]---
> >> use DB;
> >> my $dbh = DB::->connect();
> >>
> >> How can I do this?
> >
> >First, I would suggest you use a name other than 'DB', since that's
> >special -- it's purpose is for hooking into the perl debugger.
> >
> >Second, you need to subclass DBI, not merely create a container for
> >it.
> >Well, not unless you want to use AUTOLOAD to delegate all database
> >method calls to the database handle object.
> 
> What should be done when inheriting a class and wanting to be sure that
> my attribute didn't overwrite some of inherited class?

In general, there's no way to be absolutely, one hundred percent *sure*
that your attribute won't conflict with a parent class, except by
reading the source code of the parent class... even this may not be
foolproof, since the next version of the module may use different names.

There is, however, a general hueristic:  Use attribute names which are
unlikely for another class to pick for it's own attributes...


The most common, though not always foolproof, is to simply prefix all
attribute names with the name of your class, something like:

   package Foo;
   use base 'Bar';
   sub new {
      my $self = shift()->SUPER::new(@_);
      $self->{foo_firstthing} = 1;
      $self->{foo_secondthing} = 2;
      $self;
   }

Presumably, class Bar is unlikely to use an attribute matching
/^foo_.*/, though there's no garuntee that it won't do so.

For a *real* general solution -- each module should *document* what
types of attribute names it uses and might use in the future, and what
it won't possibly use in the future.  Eg, if Bar is documented to only
use attribute names /^bar_.*/, then you will *know* that /^foo_.*/ is
safe to use.

For DBI, all attribute name starting with a capital letter are reserved
for DBI itself.

Lowercase attribute names will be used by and defined by particular data
sources (DBD modules).

So your goal is to pick an attribute name which starts with a lowercase
letter and which won't conflict with any of the DBD modules.

How to do that... well, I'm not sure.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Mon, 14 Apr 2003 23:24:55 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: newline split
Message-Id: <3e9b431d.453070161@news.erols.com>

"Psyk" <sav_me_to_nospam@hotmail.com> wrote:

: I figured it out.  is there a better way of doing this
: ~~~~~~~~~~~~~
: 
: #!/usr/bin/perl -w
: $data_file="../filetoparse";
: open(DAT, $data_file) || die("Could not open file!");
: @raw_data=<DAT>;
: close(DAT);
: 
: foreach $operation (@raw_data)
: {
:  chop($operation);
:  $newline=split(/\n/ ,@operation);
: @moo[$num] = $operation;
: $num++;
: }

Yes, there is a better way, and its name is chomp().

    chomp(my @moo = @raw_data);



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

Date: 14 Apr 2003 18:28:10 -0700
From: googleartist@yahoo.com (Artist)
Subject: Perlmonks Down?
Message-Id: <de3ad953.0304141447.14b034ba@posting.google.com>

Found
 that perlmonks.org
       perlmonks.com
       perlmonk.thepen.com
 all are down.
 Can we do something about it??

artist..


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

Date: Mon, 14 Apr 2003 17:49:31 -0500
From: Dennis Fox <dfox@ia.net>
Subject: Re: regular expression substitution and perl -p -i -e
Message-Id: <v9mentmbjcg2ae@corp.supernews.com>

osx wrote:
> Hi
> 
> I've got thousands of files on my computer and I'd like to rename each so
> that they look much tidier and structured.
> 
[snip]

> perl -p -i -e 'tr/A-Z/a-z/' 'Quantum Computing.htm'
> 
> perl -p -i -e 's/([A-Z])/([a-z])/gi' Quantum\ Computing.htm
> 
> Any help would be really appreciated.
> 
> Many thanks
> 
> David

Hello David,

What you are doing with those lines is lowercasing everything inside the 
file 'Quantum computing.htm'

I believe you want to open a directory filehandle, do a 'readdir' to get 
its contents, and then use the perl 'rename' utility to rename the file.

Hope this helps,

Dennis



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

Date: Tue, 15 Apr 2003 00:40:26 +0100
From: "News" <jaco2001uk@nospamntlworld.com>
Subject: Re: regular expression substitution and perl -p -i -e
Message-Id: <ACHma.2186$FA6.27967@newsfep4-glfd.server.ntli.net>


"Dennis Fox" <dfox@ia.net> wrote in message
news:v9mentmbjcg2ae@corp.supernews.com...
> osx wrote:
> > Hi
> >
> > I've got thousands of files on my computer and I'd like to rename each
so
> > that they look much tidier and structured.
> >
> [snip]
>
> > perl -p -i -e 'tr/A-Z/a-z/' 'Quantum Computing.htm'
> >
> > perl -p -i -e 's/([A-Z])/([a-z])/gi' Quantum\ Computing.htm
> >
> > Any help would be really appreciated.
> >
> > Many thanks
> >
> > David
>
> Hello David,
>
> What you are doing with those lines is lowercasing everything inside the
> file 'Quantum computing.htm'
>
> I believe you want to open a directory filehandle, do a 'readdir' to get
> its contents, and then use the perl 'rename' utility to rename the file.
>
> Hope this helps,
>
> Dennis
>

Ah ... I understand now :)

Many thanks.

I'll try and give it a go :)

David




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

Date: Tue, 15 Apr 2003 01:55:00 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Shortcut
Message-Id: <UDJma.12516$NY1.8404@nwrddc04.gnilink.net>

Benjamin Goldberg wrote:
> "Jürgen Exner" wrote:
> [snip]
>> The OP said "swapping" and his code uses the classic way of doing it:
>> swapping the values of the two variables $a and $b by using a
>> temporary third variable $c (which is a poor choice in naming, $tmp
>> would have made his intentions clearer). And he was asking for a
>> simpler way to do this, i.e. how to swap $a and $b without the use
>> of a third variable. A very classic problem that cannot be solved in
>> e.g. C, Pacal, or Modula.
>
> [OT] Slightly untrue.  You can swap two variables in C without a third
> variable:
>
>   a ^= b;
>   b ^= a;
>   a ^= b;

Well, ok, you are right.
But that hack is direct result of C's inability to deal with data that is
larger than on word/double word.

jue




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

Date: 14 Apr 2003 20:37:30 -0700
From: cam@ntwk.net (Cameron)
Subject: Specific Regex Question
Message-Id: <e4dad21a.0304141937.583e8897@posting.google.com>

Hi All --
 
I have a comma delimited text file with records in the following format:

B4527D,91,3,PONT,BONN,"5,675.00",600,"2,470.27",,,,32103,HM,WO
                       ^^^            ^^^
Can someone show me how to strip the only the commas that fall within quotes?

Thanks,

Cameron


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

Date: Tue, 15 Apr 2003 03:18:21 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: suggestions for perl upgrade
Message-Id: <1SKma.28069$D31.3777606@news1.news.adelphia.net>


"Jeff" <jc_cann@yahoo.com> wrote in message
news:bf5acf77.0304140710.4a65da5@posting.google.com...
> Greetings.
>
> Our shop has perl 5.004_04 in production.  Yes, it's been about 5
> years since we put it there, but this version perl has been so
> successful, we haven't really needed to upgrade.  There is also the
> issue of FUD by some of our SAs regarding perl upgrades, specifically
> module dependancies.
>
> As you can imagine, we have a lot of perl code.  Some of it is in web
> applications, and a lot more is in system code - perl became our
> replacement for UNIX shell.  So, most of the work in upgrading perl
> would be for testing, in particular new versions of modules.
>
> Unfortunately, we need to upgrade perl to use the Expect perl module.
> IO-Pty does not work on Solaris unless you are on 5.005_03.
>
> So, I am fishing for comments, suggestions and war stories about
> upgrading perl.     It seems to me that we could drop in the 5.005_03
> version with a minimal amount of pain and without recompiling our
> dynamically loaded modules.  OTH, it would be nice to get to a newer
> version of perl especially since we will have to disrupt the
> environment anyway.
>
> Finally, what are general strategies used by large IT departments on
> keeping up with new versions of perl?  Mind you, we'll spend a year
> testing an OS upgrade...
>
> Thanks in advance.
> Jeff


Her are some pretty loose guidelines...

Make sure you run cpan with the "autobundle" command BEFORE you
upgrade... -- the cpan utility can retrieve a listing of your currently
installed modules and generate a bundle (listing) to recompile / reinstall
all modules you are currently using...

# cpan
cpan> -h or --help (i dont remeber)

> cpan autobundle

Then  -- if you follow the instructions (look into cpan -- its seriiously
cool for upgrading !!!) you can reinstall / recompile with something along
the lines of...

cpan> b <localbundle> force install recompile

It will save you hours and hours of time....


GP









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

Date: Mon, 14 Apr 2003 23:17:13 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: To extract a portion of a text file
Message-Id: <3E9B4122.7060702@rochester.rr.com>

John Smith wrote:

 ...
> I have a big file (C:\test.txt) with 100s of lines. Out of all the
> lines, there is a repetetive block of code and I need to extract only
> that stuff and ignore the rest of the lines in the file:
> 
> Example: (test.txt)
> --------------------
> first line...
> second line....
> .................
> Test Case :   test1_john
>                  test2_rob
> 
> Surprise Key : hi_ there
> 
> ........
> again some lines of code.....
> 
> Test Case :  test3_john
>                test5_will
>             test10_smith
> 
> Surprise Key : hi_there2
>              hi_there3
> ................
> .............
> again some lines of code...........
> ..........
> 
> -------------------------------------
> 
> Here, the fields, Test Case and Surprise key appear many times with
> different values each time. All the values for the "Test Case" and
> "Surprise Key" fileds should be added together at one place. The
> values don't follow any indentation.
> 
> Now, the out put should like as follows:
> ----------------------
> Test Case :   test1_john
>                  test2_rob
>               test3_john
>                test5_will
>             test10_smith
> 
> Surprise Key : hi_ there
>                hi_there2
>              hi_there3
> ------------------------------------------------
> 
> I have below part of script:
> 
> -----------------------------------
> #! C:/perl/bin/perl 
> 
> $file = "C:\\test.txt);
> 
> open (FILE, $file) ||  die "Can not open the file: $!";
> 
>      while (<FILE>)
>       {                     
>          next unless (/^\s*Test/.../^\s*Surprise/);
>          print $_;         
>       }
> ---------------------------------------
> 
> Now, all other junk line as well with the required output.
> 
> What should I do to get only the output that I have mentioned above?
 ...


> John
> 

You will need to collect the data if you wish to obtain the output you 
describe, since there can be instances of a key followed by instances of 
other keys, followed by more instances of the first key.

Assuming a key line consists of a key followed by a : followed by a 
value, or just a value, and that blank lines terminate a key's current 
set of values, try something like:

use strict;
use warnings;
my $file="junk286.txt";
my $key;
my %hash;
open FILE,$file or die "Can't open file $file, $!";
while(<FILE>){
    chomp;
    $key='',next if /^\s*$/;
    if(/([\w\s]+):(.*)/){
       $key=$1;
       push @{$hash{$key}},$2;
    }
    else{
       push @{$hash{$key}},$_ if $key;
    }
}
for(sort keys %hash){
    print "$_ : ".join("\n",@{$hash{$_}})."\n";
}

-- 
Bob Walton



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

Date: 14 Apr 2003 18:36:53 -0700
From: clearguy02@yahoo.com (John Smith)
Subject: Tp process a text file....
Message-Id: <500f84f3.0304141527.6077c8c7@posting.google.com>

Hi all,

I am working on the below perl script:

I have a big file (C:\test.txt) with 100s of lines. Out of all the
lines, there is a repetetive block of code and I need to extract only
that stuff and ignore the rest of the lines in the file:

Example: (test.txt)
--------------------
first line...
second line....
 .................
Test Case :   test1_john
                 test2_rob

Surprise Key : hi_ there

 ........
again some lines of code.....

Test Case :  test3_john
               test5_will
            test10_smith

Surprise Key : hi_there2
             hi_there3
 ................
 .............
again some lines of code...........
 ..........

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

Here, the fields, Test Case and Surprise key appear many times with
different values each time. All the values for the "Test Case" and
"Surprise Key" fileds should be added together at one place. The
values don't follow any indentation.

Now, the out put should like as follows:
----------------------
Test Case :   test1_john
                 test2_rob
              test3_john
               test5_will
            test10_smith

Surprise Key : hi_ there
               hi_there2
             hi_there3
------------------------------------------------

I have below part of script:

-----------------------------------
#! C:/perl/bin/perl 

$file = "C:\\test.txt);

open (FILE, $file) ||  die "Can not open the file: $!";

     while (<FILE>)
      {                     
         next unless (/^\s*Test/.../^\s*Surprise/);
         print $_;         
      }
---------------------------------------

Now, all other junk line as well with the required output.

What should I do to get only the output that I have mentioned above?

Thanks,
John


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

Date: Tue, 15 Apr 2003 03:00:29 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Tp process a text file....
Message-Id: <hBKma.73552$Xd1.25517062@news4.srv.hcvlny.cv.net>


"John Smith" <clearguy02@yahoo.com> wrote in message
news:500f84f3.0304141527.6077c8c7@posting.google.com...
> Hi all,
>
> I am working on the below perl script:
>
> I have a big file (C:\test.txt) with 100s of lines. Out of all the
> lines, there is a repetetive block of code and I need to extract only
> that stuff and ignore the rest of the lines in the file:

This is exactly what your code does.  In you example below, I have
marked (###) the lines that are printed.

>
> Example: (test.txt)
> --------------------
> first line...
> second line....
> .................
> Test Case :   test1_john     ###
>                  test2_rob         ###
>                                          ###
> Surprise Key : hi_ there     ###
>
> ........
> again some lines of code.....
>
> Test Case :  test3_john      ###
>                test5_will            ###
                                            ###
>             test10_smith         ###
>                                         ###
> Surprise Key : hi_there2   ###
>              hi_there3
> ................
> .............
> again some lines of code...........
> ..........
>
> -------------------------------------
>
> Here, the fields, Test Case and Surprise key appear many times with
> different values each time. All the values for the "Test Case" and
> "Surprise Key" fileds should be added together at one place. The
> values don't follow any indentation.
>
> Now, the out put should like as follows:

> ----------------------
> Test Case :   test1_john
>                  test2_rob
>               test3_john
>                test5_will
>             test10_smith
>
> Surprise Key : hi_ there
>                hi_there2
>              hi_there3       #### problem #####
> ------------------------------------------------

hi_there3 is not within any Test Case/Surprise Key block.  It is not
extracted.
>
> I have below part of script:
>
> -----------------------------------
> #! C:/perl/bin/perl
>
> $file = "C:\\test.txt);
>
> open (FILE, $file) ||  die "Can not open the file: $!";
>
>      while (<FILE>)
>       {
>          next unless (/^\s*Test/.../^\s*Surprise/);
>          print $_;
>       }
> ---------------------------------------
>
> Now, all other junk line as well with the required output.

The only lines that are extracted but do not appear in you sample output
are two blank lines.

>
> What should I do to get only the output that I have mentioned above?


A second pass could reformat the output. (Replace the print with a push
in the first pass)

I am afraid that I would mislead you if I say anymore before I
understand the hi_there3 problem and your reference to 'junk' lines.

Bill





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

Date: Mon, 14 Apr 2003 20:28:26 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Re: What is wrong?
Message-Id: <3E9B603A.9040306@annuna.com>

Thanks I figured it was something really stupid that I just couldn't 
see.  I hope of offer this program for distribution when it is finished. 
  I am really learning allot writing it.

Martien Verbruggen wrote:
> On Sun, 13 Apr 2003 15:19:03 -0500,
> 	Joe Creaney <mail@annuna.com> wrote:
> 
>>Here is a snippet of a program I am writing and trying to debug.  It is 
>>a simple role-playing game.  I am using objects and packages.  Right now 
>>the compiler is giving my syntax errors in my package declaration 
>>statements as marked.  I am very sure that they are not wrong but I 
>>would like some advice for finding where the errors relay are.



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

Date: Mon, 14 Apr 2003 17:52:07 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Re: Why do I get an error More code
Message-Id: <3E9B3B97.3020706@annuna.com>



Joe Creaney wrote:
> 
> 
> Uri Guttman wrote:
> 
>> because you followed up your own post with no new content.
>>
>> uri
>>
> I added more code than my first post.  What else would be helpful.  It 
> is kind of a long program.
> 
> 

Where should I look to find the error?


package Monster;
#!/usr/bin/perl -w
use strict;

new {
	my ($nm, $hd, $hp, $dam, $ac, $xpv, $x, $y) = @_;
	my $monst = {
		name => $nm,
		hd   => $hd,
		dam  => $dam,
		ac   => $ac,
		xpv  => $xpv,
		x    => $x,
		y    => $y
		};
	bless $monst;
	return $monst;			
	}

generate {

my ($player, $mx, $my) = @_;
my $v;
my @mm;
my $hp;
my @num;
my $lp = 0;
my $rm;
my $x;

my @ml = (
	[ "Rat",1,0,2,9,10 ],
	[ "Kobold",1,0,4,9,10 ],
         [ "Orc",1,0,6,8,15 ],
	[ "Skelliton",1,0,4,9,10 ],
         [ "Gobblin",1,0,7,4,10 ],
         [ "Hobgobblin",2,0,6,6,15 ],
      	[ "Wolf",2,0,6,5,20 ],
	[ "Ogre",3,0,7,5,25 ],
	[ "Troll",3,0,8,4,25 ],
	[ "Giant",3,0,3,4,8,30 ],
         [ "Dragon!",4,0,10,1,100 ],
          );

# 0 name,1 Hit dice (Level),2 Hit Points,3 Max dammage,4 Armor Class,5 
Expewrience value

$rm = int(rand(4)) + $player->{lv};
if ($rm > 10 )
         {$rm = 10; }

@mm = @ml[$rm];

for ($x=0; $mm[1]; $x++) {
         $hp += int(rand(6))+1;
         }

print "You see a $mm[0] \n";

$mm[2] = $hp;
while  ($num[$lp]->name ne " "){
	if ($num[$lp]->{name} eq " ") {
	$num[$lp] =  new (@mm, $mx, $my );
	$lp++;
		}
	}
$v = $num[$lp];
return $v, $player;

}
package Maps;   <---- Get Syntax error here now
#!/usr/bin/perl -w
use strict;


new {
	my @map1 = (
         [ qw (# # # # # # # # # # # # # # # # #)],
         [ qw (# . . . . # . . . . # . # # . # #)],
         [ qw (# # # # . # . # # . # . # . . . #)],
         [ qw (# . . . . . . . # . # . # . # . #)],
         [ qw (# . . # # . # # # . . . # . # . #)],
         [ qw (# . . # . . . # # . # . # . # # #)],
         [ qw (# # . # # . . . . . # . . . . . #)],
         [ qw (# # . . # . . # # # # # # # # . #)],
         [ qw (# # # # # # # # # # # # # # # X #)],
	);
	my $map = {
		map => @map1
		};
	bless $map;
	return $map;			
	}

packsge Main;
#!/usr/bin/perl -w
use strict;



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

Date: Tue, 15 Apr 2003 00:14:00 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Why do I get an error More code
Message-Id: <slrnb9mjm7.4ba.mgjv@verbruggen.comdyn.com.au>

On Mon, 14 Apr 2003 17:52:07 -0500,
	Joe Creaney <mail@annuna.com> wrote:
> 
> 
> Joe Creaney wrote:
>> 
>> 
>> Uri Guttman wrote:
>> 
>>> because you followed up your own post with no new content.
>>>
>>> uri
>>>
>> I added more code than my first post.  What else would be helpful.  It 
>> is kind of a long program.
>> 
>> 
> 
> Where should I look to find the error?

[snip of essentially the same broken code posted before]


Did you actually read the responses you got to earlier posts of this
same code? You have left in the same errors that have already been
corrected for you at least twice. Please, go back and find your
earlier posts and replies to that, and read them.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | Can't say that it is, 'cause it ain't.
                        | 


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

Date: Mon, 14 Apr 2003 17:30:11 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Re: Why do I get an error
Message-Id: <3E9B3673.1080909@annuna.com>



Uri Guttman wrote:
> because you followed up your own post with no new content.
> 
> uri
> 
I added more code than my first post.  What else would be helpful.  It 
is kind of a long program.




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

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 4845
***************************************


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