[22268] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4489 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 30 18:06:10 2003

Date: Thu, 30 Jan 2003 15:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 30 Jan 2003     Volume: 10 Number: 4489

Today's topics:
        $G->add_weighted_edge($u, $w, $v, $a) "the uknown $a va <a_valarakos@hotmail.com>
    Re: Attitude to Perl in academia <jpagnew@vcu.edu>
    Re: Attitude to Perl in academia Andrew Lee
    Re: Attitude to Perl in academia (Randy Kobes)
    Re: Checking for a file Andrew Lee
    Re: double pipes || (Tad McClellan)
    Re: double pipes || <blnukem@hotmail.com>
    Re: double pipes || (Tad McClellan)
        Email attachment with IO::Socket <mememe@meme.com>
        Fetchrow Question <smiley@uvgotemail.com>
    Re: Fetchrow Question <glex@qwest.net>
    Re: Fetchrow Question <me@privacy.net>
    Re: Fetchrow Question Andrew Lee
    Re: Fetchrow Question <smiley@uvgotemail.com>
    Re: Fetchrow Question <smiley@uvgotemail.com>
    Re: Fetchrow Question <jeff@vpservices.com>
        How to find @INC in a mod_perl compiled httpd binary? (Kyndig)
        How to read file as a Word document? (Julia Genyuk)
    Re: How to read file as a Word document? <tassilo.parseval@post.rwth-aachen.de>
    Re: Net::NNTP Can't call method "list" on an undefined  <Etan@none.com>
    Re: Next problem. (Jay Tilton)
        problem 'chomp' ing shell command's output <thens@nospam.com>
    Re: problem 'chomp' ing shell command's output (Anno Siegel)
    Re: problem 'chomp' ing shell command's output (Tad McClellan)
    Re: problem 'chomp' ing shell command's output Andrew Lee
        regular expression / matching (agape)
    Re: regular expression / matching (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 30 Jan 2003 23:49:52 +0200
From: "Alexandros" <a_valarakos@hotmail.com>
Subject: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $a variable"
Message-Id: <b1c6ll$1jec$1@ulysses.noc.ntua.gr>

I found the following:

   "$G->add_weighted_edge($u, $w, $v, $a)
 Adds in the graph $G an edge from vertex $u to vertex $v and the edge
attribute 'weight' set to $w."
They forgot to say something about the variable $a?????

Any suggestion?



 Thanks in advance

Alexandros





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

Date: Thu, 30 Jan 2003 14:01:56 -0500
From: Jim Agnew <jpagnew@vcu.edu>
Subject: Re: Attitude to Perl in academia
Message-Id: <3E3976A4.FE1016EF@vcu.edu>

TBN wrote:
> 
 Chainsaw....................

> Also, I could be wrong, but I've never seen a Perl version on a mainframe,
> generally just Unix/Linux and Windows and a lot of universities prefer to
> teach languages which are compiled on their VAX or Mainframe machine.  To be
> honest, I don't remember any scripting type languages being taught much.

Well, I learned Perl on my VAX. 8-D  under VAX/VMS, even.. we've had it
for oh, 
5 years.  However, it was NOT trivial to set up... but very usefull, as
well as
portable.

jim


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

Date: Thu, 30 Jan 2003 14:33:10 -0500
From: Andrew Lee
Subject: Re: Attitude to Perl in academia
Message-Id: <3uti3vcr4qc6crp2gqr83ol1ejpaqtuivk@4ax.com>

On 30 Jan 2003 09:39:03 -0800, rat_tank@yahoo.com (Rat Tank) wrote:

>I've programmed for some time in Perl, but at no time has this been
>anything to do with the CompSci degree I'm studying; no course even
>mentions it. Why is this? Perl doesn't seem to have much respect in
>educated programming circles, and I think this is why;

Pardon me if I ask those in the "educated programming circles" to kiss
my pucker :-)

Academia and the real world are unrelated ... if you have a real world
problem and you want to solve it quickly you may opt of Perl or sh or
Tcl or Python or any number of languages that an academic can't begin to
grok because they are more interested in things like design patterns,
lambda calculus or topological search algorithms (or whatever they can
write a paper on so they can feel vastly superior to the average working
programmer who makes more money than them).

>    Its type system is not entirely sound. Inference upon the typing
>rules (which aren't formally stated anywhere; I had to derive them
>from the sourcecode) can lead to propositional contradictions.

Formal set theory has propositional contradictions.  You would be hard
pressed to convince the working programmer that he/she needs to concern
themselves with such academic hot wind.

>    It is most certainly _not_ Turing complete (trivially provable);
>hence not all algorithms can be implemented in it that you could with
>a Turing complete language like Java or C(++).

Implement an algorithm to determine if a given diophantine equation is
solvable in C++ or Java (or Pascal or Lisp or Smalltalk or whatever).

Oops -- that's right -- there can be no such algorithm -- all languages
are incomplete.


>    Perl's reference counting system of garbage collection can
>sometimes result in memory leaks, as opposed to the more thorough
>graph traversal employed in other languages.

You mean Java?  Certainly there are no leaks in that language (cough).

>    Despite all this, it's frustrating that I can't get course credit
>for the various projects I've done in my own time (that would be
>perfectly acceptable as coursework if implemented in other languages).
>I know that academia is not quite the 'real world', but I'd have hoped

Not quite or not at all?

>that could be offset by just how damn useful Perl is (and I've
>demonstrated this to my profs on more than one occasion). What do you
>think?


I think your profs are professional academics and are uninterested in
getting a job done quickly and efficiently -- put them in the real world
and watch them squirm.

Personally when I am on a job with a brand new CS grad I shudder -- it
takes months or years for them to unlearn their force fed pedantry and
get down to the business of making real software that works.  The
notable exceptions are those academics who are smart enough in the first
place to be thinking beyond a degree or their next academic paper.
Those people do things like invent TCP/IP, AWK, Perl, C, Unix, Linux,
ethernet, gui etc.

Wanna see what academics do?  Look at Lotus Notes  :-)


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

Date: 30 Jan 2003 22:38:35 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: Attitude to Perl in academia
Message-Id: <slrnb3ja03.27q.randy@theoryx5.uwinnipeg.ca>

On Thu, 30 Jan 2003 14:33:10 -0500, Andrew Lee <AndrewLee> wrote:

[ ... ]
> Wanna see what academics do?  Look at Lotus Notes  :-)

Or read biographies of Alan Turing and Alonzo Church ...

-- 
best regards,
randy kobes



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

Date: Thu, 30 Jan 2003 14:42:44 -0500
From: Andrew Lee
Subject: Re: Checking for a file
Message-Id: <7tvi3vcu76thd2t5tqm3tjdvp9t708542s@4ax.com>

On Thu, 30 Jan 2003 16:37:29 GMT, "TBN" <ihave@noemail.com> wrote:

>I'm still pretty new to Perl, so bear with me on this probably simple
>question.
>
>I know that I can open a file using the following...
>open (CODE, $filename) || &OtherStuff;
>
>But I'm not really interested in opening this file. 

perldoc perlfunc

Look for -X FILEHANDLE ... the list of filetest operators.


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

Date: Thu, 30 Jan 2003 13:13:44 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: double pipes ||
Message-Id: <slrnb3iub8.kam.tadmc@magna.augustmail.com>

Blnukem <blnukem@hotmail.com> wrote:


> Why does this only return true for "bill" and not the others?


Because that is what perlop.pod says it is supposed to do.


> if ($check eq ("bill"||"john"||"rick"||"robert")) {


------------------------
=head2 C-style Logical Or

Binary "||" performs a short-circuit logical OR operation.  That is,
if the left operand is true, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it
is evaluated.

The C<||> and C<&&> operators differ from C's in that, rather than returning
0 or 1, they return the last value evaluated.
------------------------


The string "bill" is true, so none of the other alternatives
are considered, as in that first paragraph.

So the RHS of the eq operator is "bill" since that was the last
(only, in this case) expression evaluated, as in that second
paragraph.


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


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

Date: Thu, 30 Jan 2003 19:36:36 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: Re: double pipes ||
Message-Id: <89f_9.455104$FT6.93191462@news4.srv.hcvlny.cv.net>

Thanx Tad

I now I get it!

Blnukem

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb3iub8.kam.tadmc@magna.augustmail.com...
> Blnukem <blnukem@hotmail.com> wrote:
>
>
> > Why does this only return true for "bill" and not the others?
>
>
> Because that is what perlop.pod says it is supposed to do.
>
>
> > if ($check eq ("bill"||"john"||"rick"||"robert")) {
>
>
> ------------------------
> =head2 C-style Logical Or
>
> Binary "||" performs a short-circuit logical OR operation.  That is,
> if the left operand is true, the right operand is not even evaluated.
> Scalar or list context propagates down to the right operand if it
> is evaluated.
>
> The C<||> and C<&&> operators differ from C's in that, rather than
returning
> 0 or 1, they return the last value evaluated.
> ------------------------
>
>
> The string "bill" is true, so none of the other alternatives
> are considered, as in that first paragraph.
>
> So the RHS of the eq operator is "bill" since that was the last
> (only, in this case) expression evaluated, as in that second
> paragraph.
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




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

Date: Thu, 30 Jan 2003 15:09:20 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: double pipes ||
Message-Id: <slrnb3j540.kjj.tadmc@magna.augustmail.com>

Blnukem <blnukem@hotmail.com> wrote:

> Thanx Tad


You are welcome.

I've asked before that you begin to quote your followups properly.

Please see the Posting Guidelines that are posted here frequently.

One more top-post and all your future posts will become invisible to me.


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


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

Date: Thu, 30 Jan 2003 15:33:11 -0700
From: "ColdCathoids" <mememe@meme.com>
Subject: Email attachment with IO::Socket
Message-Id: <b1c97c$11qmld$1@ID-158028.news.dfncis.de>

Hello all,

First off thanks to everyone who helped me with my more random then random
question earlier this week! Works exactly how I wanted. Now I have another
question.

I am writing a small app that sends out an email when a co-worker moves
files. The box this runs on is somewhat limited with modules so I was forced
to use IO::Socket to send email. It's working fine but I was wondering if
anyone knew of a way I could send email attachments using the sub below. I
am not able to install any modules on this box so I have to work with what I
got. Any thoughts?



sub sendMail {
  my ($host, $from, $to, $subject, $message) = @_;
  require IO::Socket;
  my $remote = IO::Socket::INET->new(
                      Proto    => "tcp",
                      PeerAddr => $host,
                      PeerPort => "smtp(25)",
                  )
                or die $!;
  my $debug = <$remote>;
  print $remote "MAIL FROM: $from\n";
  $debug .= <$remote>;
  print $remote "RCPT TO: $to\n";
  $debug .= <$remote>;
  print $remote "DATA\n";
  $debug .= <$remote>;
  print $remote "From: $from\nTo: $to\nSubject: $subject\n\n";
  print $remote "$message\n";
  print $remote ".\n";
  $debug .= <$remote>;
  close $remote;
  return $debug;
}




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

Date: Thu, 30 Jan 2003 14:27:41 -0500
From: "Smiley" <smiley@uvgotemail.com>
Subject: Fetchrow Question
Message-Id: <v3iv5ob6sa0u36@corp.supernews.com>

I've been using the recommended method for accessing data that is described
in my reference books: fetchrow_array

I was thinking, though, that a hash would be better suited to some of the
programming I'm doing, and though I couldn't find reference to that in the
books I have, sources online have led me to believe that I coudl use
fetchrow_hash.

It doesn't seem to work though, I get the following error in my error log:

Can't locate object method "fetchrow_hash" via package "DBI::st" at
changedata.cgi line 123.

This is the line I used:

my %userdata=$sth->fetchrow_hash();

Can anybody tell me how I can make this work?






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

Date: Thu, 30 Jan 2003 14:31:59 -0600
From: Jeff D Gleixner <glex@qwest.net>
Subject: Re: Fetchrow Question
Message-Id: <mXf_9.557$HP6.54731@news.uswest.net>


> Can't locate object method "fetchrow_hash" via package "DBI::st" at
> changedata.cgi line 123.
> 
> This is the line I used:
> 
> my %userdata=$sth->fetchrow_hash();
> 
> Can anybody tell me how I can make this work?

Of course, however you can find the answer to that and a lot more
in the DBI documentation.

perldoc DBI
-- 
Jeff Gleixner
Bumper Sticker of the moment:
	Okay, who stopped payment on my reality check?



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

Date: Fri, 31 Jan 2003 08:39:23 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Fetchrow Question
Message-Id: <b1c62f$11e6cu$1@ID-172104.news.dfncis.de>


"Smiley" <smiley@uvgotemail.com> wrote in message
news:v3iv5ob6sa0u36@corp.supernews.com...
[snip of repeated question in alt.perl and possibly other groups]

Please read http://www.cs.tut.fi/~jkorpela/usenet/xpost.html




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

Date: Thu, 30 Jan 2003 16:39:38 -0500
From: Andrew Lee
Subject: Re: Fetchrow Question
Message-Id: <hp6j3vgh20q65e092v49r6e5kluiq8mmed@4ax.com>

On Thu, 30 Jan 2003 14:27:41 -0500, "Smiley" <smiley@uvgotemail.com>
wrote:

>I've been using the recommended method for accessing data that is described
>in my reference books: fetchrow_array
>
>I was thinking, though, that a hash would be better suited to some of the
>programming I'm doing, and though I couldn't find reference to that in the
>books I have, sources online have led me to believe that I coudl use
>fetchrow_hash.

perldoc DBI, see fetchrow_hashref

Always favor the documentation that comes with Perl over a book.




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

Date: Thu, 30 Jan 2003 16:50:39 -0500
From: "Smiley" <smiley@uvgotemail.com>
Subject: Re: Fetchrow Question
Message-Id: <v3j7hnilpp4f77@corp.supernews.com>

> Of course, however you can find the answer to that and a lot more
> in the DBI documentation.
>
> perldoc DBI

Yes, I've looked through the documentation, I haven't yet found any examples
to help me straighten this out.  If there's something I missed, then I'd be
grateful for any assistance, that's the reason why I posted here.  If you
can give me actual examples I'll appreciate that a whole lot more, thanks :)




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

Date: Thu, 30 Jan 2003 16:54:49 -0500
From: "Smiley" <smiley@uvgotemail.com>
Subject: Re: Fetchrow Question
Message-Id: <v3j7phc7fgkp3a@corp.supernews.com>

"Tintin" <me@privacy.net> wrote in message
news:b1c62f$11e6cu$1@ID-172104.news.dfncis.de...
>
> "Smiley" <smiley@uvgotemail.com> wrote in message
> news:v3iv5ob6sa0u36@corp.supernews.com...
> [snip of repeated question in alt.perl and possibly other groups]
>
> Please read http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
>

Thank you, but I do know how to crosspost.  Something went wrong when I
tried to crosspost this message, I'm not sure what, so I decided to try
posting to each group individually.  It seems that one of the groups didn't
get my messages, I didn't know that could hold back the postings for all of
the other groups (doesn't make sense to me, but that seems to be the way it
works).  In any case, I've localized which newsgroup was the problem by
posting to each in turn - sorry if it's caused you any inconvenience.




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

Date: Thu, 30 Jan 2003 14:49:41 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Fetchrow Question
Message-Id: <3E39AC05.6070802@vpservices.com>

Smiley wrote:


> 
> my %userdata=$sth->fetchrow_hash();

There is no such method as "fetchrow_hash()".  There is one called 
"fetchrow_hashref()" which returns, surprise, a hashref instead of a 
hash.  So change your line to

    my $userdata = $sth->fetchrow_hashref();

-- 
Jeff



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

Date: 30 Jan 2003 14:43:38 -0800
From: kyndig@knife-fighting.com (Kyndig)
Subject: How to find @INC in a mod_perl compiled httpd binary?
Message-Id: <ed882ecb.0301301443.2defc68c@posting.google.com>

Could someone please help me find the @INC path of mod_perl which is
already statically compiled into an Apache httpd binary?

I'm upgrading an Apache server, but my newly compiled binary gives me
a "Can't locate foo.pm in @INC" because the hard coded @INC path is
aparently different than that of the original binary.

I know the problem can be fixed by setting @INC or perl5libs or "use
lib ...", but I want to change as little as possible; thus I need to
know how to find the @INC of the old binary and how to set it(during
compilation) on the new one to match.  As I said, mod_perl is compiled
in statically.  Any help is greatly appreciated !


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

Date: 30 Jan 2003 13:44:54 -0800
From: jgenyuk@ucar.edu (Julia Genyuk)
Subject: How to read file as a Word document?
Message-Id: <9c9b427e.0301301344.51326360@posting.google.com>

This question probably belongs to some other group but there are
certainly experts here who know everything...
I'm trying to write a script which will force an html file to appear
as aWord file to a browser. I did a simple thing:

print "Content-type: application/msword\n\n";
print $html;

$html contains the actual html script. It works very inconsistently,
however,
especially if I try to call this script several times in a row. Any
other suggestions? Thanks.

Julia


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

Date: 30 Jan 2003 22:28:02 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: How to read file as a Word document?
Message-Id: <b1c8ti$2oc$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Julia Genyuk:

> This question probably belongs to some other group but there are

Yes...

> certainly experts here who know everything...

 ...but since these experts respect the rules of this group they will
only share their Perl-knowledge in this group.

> I'm trying to write a script which will force an html file to appear
> as aWord file to a browser. I did a simple thing:

[...]

I suggest you ask this in the appropriate group, possibly one with
'infosystem' in its name.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 30 Jan 2003 21:00:59 GMT
From: "Etan" <Etan@none.com>
Subject: Re: Net::NNTP Can't call method "list" on an undefined value
Message-Id: <fog_9.552384$y74.3876551@news.easynews.com>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:b1aunm$fed$1@mamenchi.zrz.TU-Berlin.DE...
> Etan <Etan@none.com> wrote in comp.lang.perl.misc:
> > I have a script the gets the list of newsgroups and article counts off
of a
> > news server.  It worked fine on the previous host.  I changed hosts, and
now
> > I get the error message "Can't call method "list" on an undefined
value."
> > What is wrong? What value is undefined? I reduced the code to its
simplest
> > as follows, and still get the error message:
> >
> > #!/usr/bin/perl
> > use Net::NNTP;
> > $nntp = Net::NNTP->new("news.xxxx.com");
> > my $grpsref = $nntp->list();
>
> Apparently the NNTP server (represented by "news.xxxx.com") doesn't
> give you access.  Net::NNTP->new() returns a false value in this case.
>
> Catch the error:
>
>     my $nntp = Net::NNTP->new( 'news.xxxx.com') or die "no connection:
$!";
>
> Anno

That fixes it, thanks.  Looks like the new host couldn't resolve the DNS, so
I use the IP number instead and now it works.




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

Date: Thu, 30 Jan 2003 22:48:51 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Next problem.
Message-Id: <3e39ab1e.385511447@news.erols.com>

"Jürgen Exner" <jurgenex@hotmail.com> wrote:

: Tad McClellan wrote:
: > Jürgen Exner <jurgenex@hotmail.com> wrote:
: >> Richard S Beckett wrote:
: >
: >>>     next if  ($_ eq ('Fred' || 'Wilma'));
: >
: >> BTW: I think if you would have used warnings then perl would have
: >> warned you about his blunder.
: >
: > Nope, warnings won't catch that one.
: 
: Hmm, I wonder if they should.
:
: Considering that this mistake pops up about every month it may be worth
: thinking about a change in warnings.

    H>perl -MO=Deparse -e "print('Fred'||'Wilma')"
    print 'Fred';
    -e syntax OK

So perl is already smart enough to recognize when this is happening
and optimize away the fluff.  Is there a mechanism available to hook
warnings into this stage?



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

Date: Fri, 31 Jan 2003 00:45:02 +0530
From: Thens <thens@nospam.com>
Subject: problem 'chomp' ing shell command's output
Message-Id: <20030131004502.6c890c51.thens@nospam.com>

Hi  
   Iam trying to chomp the output of a shell command executed inside a
perl program. Here goes my script

#! /usr/local/bin/perl -w


use strict;
use Data::Dumper;

my @allCFiles = `find . -name "*.c"`;
print Data::Dumper->Dump( [\@allCFiles], ["allCFiles"] );

@allCFiles = map { chomp } @allCFiles;
print Data::Dumper->Dump( [\@allCFiles],["allCFiles"] );

__END__


Output:
$allCFiles = [
               './foo.c
',
               './bar.c
',
               './main.c
'
             ];
$allCFiles = [
               1,
               1,
               1
             ];

 What is that iam doing wrong here ??

- Thens


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

Date: 30 Jan 2003 21:10:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: problem 'chomp' ing shell command's output
Message-Id: <b1c4co$goh$1@mamenchi.zrz.TU-Berlin.DE>

Thens  <thens@nospam.com> wrote in comp.lang.perl.misc:
> Hi  
>    Iam trying to chomp the output of a shell command executed inside a
> perl program. Here goes my script

[...]

> @allCFiles = map { chomp } @allCFiles;

You should read the documentation of the function that gives you trouble:
"perldoc -f chomp".  Take note of what chomp() returns (it is *not* the
chomped string, everyone fell for that once).  Take also note of what
chomp() does when given a list of arguments.  You'll find that the right
way to run chomp over a list of lines is

    chomp @allCFiles;

Anno


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

Date: Thu, 30 Jan 2003 15:20:36 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: problem 'chomp' ing shell command's output
Message-Id: <slrnb3j5p4.kjj.tadmc@magna.augustmail.com>

Thens <thens@nospam.com> wrote:

>    Iam trying to chomp the output of a shell command executed inside a
> perl program.


> my @allCFiles = `find . -name "*.c"`;


> @allCFiles = map { chomp } @allCFiles;


You can replace that erroneous line with simply:

   chomp @allCFiles;


>  What is that iam doing wrong here ??


Not reading the documentation for the function you are using.

   perldoc -f chomp

      It returns the total number of characters removed from 
      all its arguments.
      ...
      If you chomp a list, each element is chomped


Inside of the map block it removes one character from $_, and
returns 1, so a bunch of ones is what you get back from the map.


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


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

Date: Thu, 30 Jan 2003 16:56:01 -0500
From: Andrew Lee
Subject: Re: problem 'chomp' ing shell command's output
Message-Id: <8l7j3v4131mh72gq5jrbku8r5j7rlj295u@4ax.com>

On Fri, 31 Jan 2003 00:45:02 +0530, Thens <thens@nospam.com> wrote:

>Hi  
>   Iam trying to chomp the output of a shell command executed inside a
>perl program. Here goes my script
>
>#! /usr/local/bin/perl -w
>
>
>use strict;
>use Data::Dumper;
>
>my @allCFiles = `find . -name "*.c"`;
>print Data::Dumper->Dump( [\@allCFiles], ["allCFiles"] );
>
>@allCFiles = map { chomp } @allCFiles;
>print Data::Dumper->Dump( [\@allCFiles],["allCFiles"] );
>
>__END__
>

That's not how you want to use chomp ...
From the docs :
If you chomp a list, each element is chomped, and the total
number of characters removed is returned.  

So there is one newline in every element of @allCFiles (but you knoew
that).

Just do :

my @allCFiles = `find . -name "*.c"`;
chomp @allCFiles;
print join "\n", @allCFiles;




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

Date: 30 Jan 2003 13:18:42 -0800
From: bionic_man1@yahoo.com (agape)
Subject: regular expression / matching
Message-Id: <3e5aae09.0301301318.f8ed83@posting.google.com>

Thanks those who helped in the following search:

I have a file with thousands of records as such:
-term1 /my/home/directory -term2 a.v -term3 15000 -last "var1 var2
var3 var4" -t4 /my/current/  -last_one "variable1 variable2" -term4
xyz


The above could be in any order but any switch(-term1 or -term2 or
-last and so forth) is followed by a value of some sort. 

on one of the field say :  -b abcdev.m,v  I am trying to capture the
value that is passed to "-b" and remove the "-b" itself.  so the
result should be abcdev.m,v

My script works if I have:

$captured_test =~ s/-b//;
But, once it sees ",v" at the end of abcdev.m,v , then it ignores the
rest of the record or entry. Any idea?

Agape


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

Date: 30 Jan 2003 22:41:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regular expression / matching
Message-Id: <b1c9mm$kop$1@mamenchi.zrz.TU-Berlin.DE>

agape <bionic_man1@yahoo.com> wrote in comp.lang.perl.misc:
> Thanks those who helped in the following search:
> 
> I have a file with thousands of records as such:
                                  ^^^^^^^
> -term1 /my/home/directory -term2 a.v -term3 15000 -last "var1 var2
> var3 var4" -t4 /my/current/  -last_one "variable1 variable2" -term4
> xyz

You don't say how to tell one record from another.  I'll assume each
record is on one line and you have broken the data for Usenet.  If
you do that, please say so.

> The above could be in any order but any switch(-term1 or -term2 or
> -last and so forth) is followed by a value of some sort. 
> 
> on one of the field say :  -b abcdev.m,v  I am trying to capture the
> value that is passed to "-b" and remove the "-b" itself.  so the
> result should be abcdev.m,v
> 
> My script works if I have:
> 
> $captured_test =~ s/-b//;
> But, once it sees ",v" at the end of abcdev.m,v , then it ignores the
> rest of the record or entry. Any idea?

I don't see how the comma (with or without "v") should be a problem.

Your main problem are the embedded blanks in quoted strings, which
are apparently supposed to be treated as a unit.  You'll want to use
Text::ParseWords from the standard distribution for that, but also
see the faq "perldoc -q 'except when inside'".

This will give you a list (say @terms) of alternately a keyword (with
leading "-") and a value (possibly multi-word).  This is for well-formed
input.

Your next step will be to make the keyword-value associations (a hash
suggests itself).  Assuming good input, this is as simple as

    my %values = @terms;

If you must check things, do it step-wise, working on a pair a time

    my %values;
    while ( @terms ) {
        my $key = shift @terms;
        die "bad keyword" unless $key =~ /^-/; # or whatever
        die "short data" unless @terms;
        my $value = shift @terms;
        # further checks
        # ...
        $values{ $key} = $value;
    }

If you actually need the string of all values without the keys...,
well, I guess if you're at this point, you'll probably see for
yourself how to get it.

Anno


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4489
***************************************


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