[28366] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9730 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 15 18:05:45 2006

Date: Fri, 15 Sep 2006 15:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 15 Sep 2006     Volume: 10 Number: 9730

Today's topics:
    Re: Column extraction in perl <xicheng@gmail.com>
    Re: Column extraction in perl <someone@example.com>
    Re: exec command issue <don@mastah.com>
    Re: exec command issue <mritty@gmail.com>
        in-memory plot <maitrebart@excite.com>
        Learning perl - for experienced programmers <strombrg@dcs.nac.uci.edu>
    Re: Learning perl - for experienced programmers <mritty@gmail.com>
    Re: Learning perl - for experienced programmers cartercc@gmail.com
    Re: Learning perl - for experienced programmers <john@castleamber.com>
    Re: Learning perl - for experienced programmers (Randal L. Schwartz)
    Re: Maximum number of sockets <angusma@attglobal.net>
        Perl code to substituting one line in file cindyybl@gmail.com
    Re: Perl code to substituting one line in file <glex_no-spam@qwest-spam-no.invalid>
    Re: Perl code to substituting one line in file <jl_post@hotmail.com>
    Re: String buffer instead of file handle? <danparker276@yahoo.com>
    Re: String buffer instead of file handle? <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 15 Sep 2006 11:17:12 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: Column extraction in perl
Message-Id: <1158344231.590117.231750@k70g2000cwa.googlegroups.com>

vkrish7@gmail.com wrote:
> Hello all,
> I am very new to PERL and need some help here to get this going...
>
> I have about 100 text files and each text file looks something like
> this:-
>
> V_or_I   Lo_BIT
>   5330        1
>   5380        5
>   5390        6
>   5400        9
>   5410       11
>   5420       15
>
> Now  i need to grab only the first column starting with (5330, skip
> "V_or_I" line) go till the end of the file(Say till 5420) and write
> this to another file(say dataappend.txt). Then open another text file(
> out of 100 text files) do the same( ie. start from second line of the
> file which will be in number format similar to 5330 and grab the first
> column and append to dataappend.txt... Can any1 please show me how to
> do this on perl?

perl -ln0777e 'print for /^(?!\A)\s*(\S+)/mg' file* > dataappend.txt

Xicheng



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

Date: Fri, 15 Sep 2006 18:35:48 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Column extraction in perl
Message-Id: <8oCOg.12529$Lb5.6915@edtnps89>

vkrish7@gmail.com wrote:
> 
> I have about 100 text files and each text file looks something like
> this:-
> 
> V_or_I   Lo_BIT
>   5330        1
>   5380        5
>   5390        6
>   5400        9
>   5410       11
>   5420       15
> 
> Now  i need to grab only the first column starting with (5330, skip
> "V_or_I" line) go till the end of the file(Say till 5420) and write
> this to another file(say dataappend.txt). Then open another text file(
> out of 100 text files) do the same( ie. start from second line of the
> file which will be in number format similar to 5330 and grab the first
> column and append to dataappend.txt... Can any1 please show me how to
> do this on perl?


perl -lne'/^\s*(\d+)\s/ && print $1' *.txt > dataappend.txt



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 15 Sep 2006 19:22:43 +0100
From: "Don Corleone" <don@mastah.com>
Subject: Re: exec command issue
Message-Id: <QMudncIeFfsLcpfYRVnyrA@giganews.com>

Thanks a million!!

This works exactly how i wanted!!!!

I just wish i understood the program flow, if you dont mind explaining what 
this does:

$path=shift

what does the shift mean ?

thanks Michele you rox!

Don



"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message 
news:5ebag29vnr01bhlajnlviodap1s0usa274@4ax.com...
> On Mon, 11 Sep 2006 08:25:11 +0100, "Don Corleone" <don@mastah.com>
> wrote:
>
>>1. get a directory name (works ok)
>
> Sorts of.
>
>>2. Get a list of all the tif files in this directory (works ok)
>
> As of your other post, it doesn't. You do *not* get the list. You
> print the listing to STDOUT.
>
>>3. perform a msdos file operation on each file returned by 2 above (doesnt
>>work).
>
>  #/usr/bin/perl
>
>  use strict;
>  use warnings;
>  use File::Spec;
>
>  die 'Usage: $0 <dir>' unless @ARGV==1;
>  chomp(my $path=shift);
>  die "$path: not a directory!" unless -d $path;
>
>  system "mdoscommand $_"
>    for glob File::Spec->catfile($path, '*.tif');
>
>  __END__
>
> But if the msdos file operation is a 'move', then you may either want
> a simple rename() if you are sure it won't cross filesystem's
> boundaries, or File::Copy's move() otherwise.
>
>
> Michele
> -- 
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH, 




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

Date: 15 Sep 2006 11:28:10 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: exec command issue
Message-Id: <1158344890.188331.10240@m73g2000cwd.googlegroups.com>

Don Corleone wrote:

> I just wish i understood the program flow, if you dont mind explaining what
> this does:
>
> $path=shift
>
> what does the shift mean ?

Perhaps you are not aware, but Perl comes with a very good set of
documentation.  From the command line that you are running your program
from, you can type:

perldoc -f shift

To get the documentation for the shift function.

For the full range of what perldoc can do, go to your command prompt
and type:

perldoc perldoc

Hope this helps,
Paul Lalli



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

Date: 15 Sep 2006 14:41:48 -0700
From: "Maitre Bart" <maitrebart@excite.com>
Subject: in-memory plot
Message-Id: <1158356508.413477.195890@i42g2000cwa.googlegroups.com>

I would like to create a XY plot and put it in a html-like email.

1) I am looking for a lib (or a set of libs) that allows to create a XY
plot (or any other kind) where I can save the resulting graphic in a
 .png file. Though I expect this is achievable in more than one step.

2) I will then manage to create a html file with the appropriate
content (that will reference my graphic files).

3) Send the html page by email.

I would appreciate suggestions to accomplish steps #1 and #3, since I
have enough experience and knowledge to perform step #2.

Thank you.



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

Date: Fri, 15 Sep 2006 21:02:05 GMT
From: Dan Stromberg <strombrg@dcs.nac.uci.edu>
Subject: Learning perl - for experienced programmers
Message-Id: <pan.2006.09.15.21.02.26.903850@dcs.nac.uci.edu>


Hi folks.

I know a variety of languages, from assemblers to VHLL's, but I'd like to
learn at least the fundamentals of perl 5.

I'd like to find a web article, magazine article or brief book that will
provide a very dense, pithy introduction.

I don't want a bunch of long examples, which seems to rule out the black
book - I can figure out how to combine things fine, and I feel like long
examples usually get far away from the heart of matters.  Just code
snippets is fine.

For example, my favorite introduction to a language was the dense
introduction to C in an appendix at the back of Andrew Tanenbaum's Minix
book - is there something like that for perl?  It might even come under
the name of a reference, perhaps.

Is such a resource available?



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

Date: 15 Sep 2006 14:06:30 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Learning perl - for experienced programmers
Message-Id: <1158354390.696854.326320@k70g2000cwa.googlegroups.com>

Dan Stromberg wrote:
> I know a variety of languages, from assemblers to VHLL's, but I'd like to
> learn at least the fundamentals of perl 5.
>
> I'd like to find a web article, magazine article or brief book that will
> provide a very dense, pithy introduction.

I suggest the following:
http://perldoc.perl.org/perlintro.html for a brief introduction to the
syntax of the language
http://perldoc.perl.org/perlretut.html for a tutorial of Regular
Expressions, which are somewhat unique to Perl, and
http://perldoc.pelr.org/perlfunc.html to have handy to look up what
functions exist (but I wouldn't recommend actually reading the whole
thing top to bottom).

Paul Lalli



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

Date: 15 Sep 2006 14:34:30 -0700
From: cartercc@gmail.com
Subject: Re: Learning perl - for experienced programmers
Message-Id: <1158356069.943010.106470@h48g2000cwc.googlegroups.com>

Dan Stromberg wrote:
> Hi folks.
>
> I know a variety of languages, from assemblers to VHLL's, but I'd like to
> learn at least the fundamentals of perl 5.

For two good, quick reads, I'd recommend the O'Reilly books, Learning
Perl and Learning Perl Objects and Modules, both by Schwartz. Each
chapter can be digested in about half an hour (for an experienced
programmer) and contains several useful exercies. Additionally, they
can be picked up used for very good prices.

In my job, I use ColdFusion, Perl, and Java. Each language has its good
uses and bad uses. Perl is very good for one off scripts of less than
25 - 50 lines. In fact, it's very, very good for that. If you're
dealing with an application of 100 lines or more that will stick around
for a while, I'd run like hell from Perl. (Within the past year, I
inherited a great mass of Perl scripts, around 70 or so, each
containing 500 or more lines of code, and it's absolutely not
maintainable, nor maintained. As it breaks, we are rewriting in
something else.)

I love Perl, but I think of it as a finely tuned sports car. If you're
hauling building materials, get a truck.

CC



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

Date: 15 Sep 2006 21:43:09 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Learning perl - for experienced programmers
Message-Id: <Xns983FAA1111068castleamber@130.133.1.4>

Dan Stromberg <strombrg@dcs.nac.uci.edu> wrote:


> book - is there something like that for perl?  It might even come under
> the name of a reference, perhaps.
> 
> Is such a resource available?

Programming Perl, 3rd edition. It's a tough read, but worth it and IMO 
matches exactly your description (been there, done that, only with the 
purple version).

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 15 Sep 2006 14:54:34 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: cartercc@gmail.com
Subject: Re: Learning perl - for experienced programmers
Message-Id: <86ac50x0bp.fsf@blue.stonehenge.com>

>>>>> "cartercc" == cartercc  <cartercc@gmail.com> writes:

cartercc> For two good, quick reads, I'd recommend the O'Reilly books, Learning
cartercc> Perl and Learning Perl Objects and Modules, both by Schwartz. Each
cartercc> chapter can be digested in about half an hour (for an experienced
cartercc> programmer) and contains several useful exercies. Additionally, they
cartercc> can be picked up used for very good prices.

The latter is now named "Intermediate Perl".  We optimized The Name That Was
Too Long To Pronounce into something much more apropos.

In addition to those, I have nearly 250 magazine articles at
http://www.stonehenge.com/merlyn/columns.html that are free for the reading.

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!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Fri, 15 Sep 2006 16:35:38 -0400
From: "A Ma" <angusma@attglobal.net>
Subject: Re: Maximum number of sockets
Message-Id: <450b0ea0@kcnews01>

"Sisyphus" <sisyphus1@nomail.afraid.org> wrote in message 
news:450a0b62$0$11969$afc38c87@news.optusnet.com.au...
>
>
> Anyway - first check to see just what the actual value of PERL_FD_SETSIZE
> is.
>

A few updates:

1. I discovered that my immediate problem is unrelated to FD_SETSIZE. It 
turns out that I had a problem with IO::Select. In my test program, if I do 
the following instead:

my $pselect1 = IO::Select->new();
my $pselect2 = IO::Select->new();

for ($i=0;$i<=49;$i++) {
 my $port = $i + 500;
 if ($server1[$i] = IO::Socket::INET->new(LocalPort => $port,
   Type      => SOCK_STREAM,
   Reuse     => 1,
   Listen    => 10 )) {
  $pselect1->add($server1[$i]);
 } else {
  print "Cannot open port $port.\n";
  $server1[$i] = 0;
 }

 $port = $i + 550;
 if ($server2[$i] = IO::Socket::INET->new(LocalPort => $port,
   Type      => SOCK_STREAM,
   Reuse     => 1,
   Listen    => 10 )) {
  $pselect2->add($server2[$i]);
 } else {
  print "Cannot open port $port.\n";
  $server2[$i] = 0;
 }
}

then I can access all 100 ports. So IO::Select is limiting me to 64 sockets.


2. I wasn't able to run the In line C code. It seems to want to use "cl" as 
the C compiler whereas I only have gcc from Mingw. I even tried copying 
gcc.exe as cl.exe but the compiler options are different. I don't know how 
to tell Inline to use a different compiler.


3. My original ActiveState Perl was installed in c:\perl. When I compiled my 
own version, I changed INST_TOP to put it in c:\perl1. Then I changed the 
path to point to c:\perl1\bin. But I think it is still going back to c:\perl 
to look for some files. How do I switch between two different versions of 
Perl?





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

Date: 15 Sep 2006 12:02:28 -0700
From: cindyybl@gmail.com
Subject: Perl code to substituting one line in file
Message-Id: <1158346948.399411.163240@b28g2000cwb.googlegroups.com>

I am trying to edit a file in my perl program. Basically, the operation
is to substitute one line in that file. But I thought that file
read/write is too complicated and tedious for a simple task like this.

There is a one-liner to substitute text in selected file on command
line.  And this is
perl -pi -e "s/pattern1/pattern2/g" filename

Well, I can always use back tick to exec this line in my program, but
is there a simple piece of perl code that will just do the same as that
in a perl program?  
Thanks.



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

Date: Fri, 15 Sep 2006 15:37:16 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Perl code to substituting one line in file
Message-Id: <450b0e28$0$10298$815e3792@news.qwest.net>

cindyybl@gmail.com wrote:
> I am trying to edit a file in my perl program. Basically, the operation
> is to substitute one line in that file. But I thought that file
> read/write is too complicated and tedious for a simple task like this.

Ahhhh.. without file read/write how would you modify the contents of a file?

> 
> There is a one-liner to substitute text in selected file on command
> line.  And this is
> perl -pi -e "s/pattern1/pattern2/g" filename
> 
> Well, I can always use back tick to exec this line in my program, but
> is there a simple piece of perl code that will just do the same as that
> in a perl program?  

That is a perl program.

You won't get any shorter than that. This should answer all your questions.

perldoc -f open

It'd be 2 open()'s, a while loop, the substitution on each line, and 
writing each line out to a file.

Also, perldoc perlrun, look for 'overwrite' and you'll see something 
such as:

"From the shell, saying

     $ perl -p -i.orig -e "s/foo/bar/; ... "

is the same as using the program: ..."

Post what you have tried.

If you want something short and sweet, check out the IO::All module, 
however by the time you download, install, and read the documentation, 
you could have written a short script to do it.


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

Date: 15 Sep 2006 14:41:42 -0700
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Perl code to substituting one line in file
Message-Id: <1158356502.385607.314700@m73g2000cwd.googlegroups.com>

cindyybl@gmail.com wrote:
>
> I am trying to edit a file in my perl program. Basically, the operation
> is to substitute one line in that file. But I thought that file
> read/write is too complicated and tedious for a simple task like this.
>
> There is a one-liner to substitute text in selected file on command
> line.  And this is
> perl -pi -e "s/pattern1/pattern2/g" filename

   Try this:

      # Replace "pattern1" with "pattern2" in file "filename":
      {local($^I,@ARGV)=("","filename"); s/pattern1/pattern2/g,print
while <>}

Note that the "I" in "$^I" is a capital "I" (eye) and not a lower-case
"l" (ell).

   This line of code (technically more than one, but who's counting?)
sets the inplace-edit extension (which is mentioned in "perldoc
perlvar").  Since the above line of code sets it to something other
than undef, in-place editing will happen on all files specified in what
we just set @ARGV to be (in this case, ("filename")).

   Also note the use of local().  We used it so that the previous
values of $^I and @ARGV would be restored at the end of the block.

> Well, I can always use back tick to exec this line in my program, but
> is there a simple piece of perl code that will just do the same as that
> in a perl program?

   Don't use backticks here.  Use a call to system() instead.  To
understand why, read "perldoc -q backticks".

   I hope this helps, Cindy.

   -- Jean-Luc



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

Date: 15 Sep 2006 11:12:59 -0700
From: "danparker276@yahoo.com" <danparker276@yahoo.com>
Subject: Re: String buffer instead of file handle?
Message-Id: <1158343979.521603.18820@i3g2000cwc.googlegroups.com>


Uri Guttman wrote:
> >>>>> "dc" == danparker276@yahoo com <danparker276@yahoo.com> writes:
>
>   dc> actually, I just like to cause trouble.  It's pretty funny sometimes.
>   dc> A read the docs post is useless post though, why even post that at all.
>
> cause smart people (unlike you) actually will go read the referenced
> doc. it is useful but you wouldn't know that. now please go learn python
> and try to be funny there. they appreciate people like you.
>
> and stop top posting. but better yet, stop posting here. we are tired of
> you and you were never entertaining.
>
See there you go again.  IT IS NOT IN MY DOCS, because I have an older
version of perl.  My solution is to change my module to use a string
instead of a file handle.  It's easier to change the module than go
through all that other hassle.
You people here are so uptight.


> 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: Fri, 15 Sep 2006 15:39:36 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: String buffer instead of file handle?
Message-Id: <x7odtg2a2v.fsf@mail.sysarch.com>

>>>>> "dc" == danparker276@yahoo com <danparker276@yahoo.com> writes:

  dc> Uri Guttman wrote:
  >> >>>>> "dc" == danparker276@yahoo com <danparker276@yahoo.com> writes:
  >> 
  dc> actually, I just like to cause trouble.  It's pretty funny sometimes.
  dc> A read the docs post is useless post though, why even post that at all.
  >> 
  >> cause smart people (unlike you) actually will go read the referenced
  >> doc. it is useful but you wouldn't know that. now please go learn python
  >> and try to be funny there. they appreciate people like you.
  >> 
  >> and stop top posting. but better yet, stop posting here. we are tired of
  >> you and you were never entertaining.
  >> 
  dc> See there you go again.  IT IS NOT IN MY DOCS, because I have an older
  dc> version of perl.  My solution is to change my module to use a string
  dc> instead of a file handle.  It's easier to change the module than go
  dc> through all that other hassle.

then you can still figure that out from the newer docs on the web. but
the idea of pointing to the docs is still valid.

  dc> You people here are so uptight.

and you are too cool for us. so please shine your light elsewhere. your
eminence is slumming here. we are not worthy.

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: 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 9730
***************************************


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