[28574] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9938 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 7 11:05:49 2006

Date: Tue, 7 Nov 2006 08:05:07 -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           Tue, 7 Nov 2006     Volume: 10 Number: 9938

Today's topics:
    Re: $var=... <wahab-mail@gmx.de>
        $var=<STDIN>; chomp($var); if (($var =~ /^./) = ($var = <olaf@yahoo.es>
    Re: $var=<STDIN>; chomp($var); if (($var =~ /^./) = ($v <someone@example.com>
    Re: Data plotting questions   Nov. 2, 2006 <edgrsprj@ix.netcom.com>
    Re: Help in regular expression <someone@example.com>
    Re: Help in regular expression <shafa.fahad@gmail.com>
    Re: Keep getting error with email validation script <tadmc@augustmail.com>
        Perl and XML Question <kenbrow@bellsouth.net>
    Re: Perl and XML Question <glex_no-spam@qwest-spam-no.invalid>
    Re: Perl with setuid enabled <prattm@gmail.com>
    Re: process subregions on an image/matrix xhoster@gmail.com
    Re: Putting a line in a specific place in a file <bryan@worldspice.net>
    Re: Putting a line in a specific place in a file <veatchla@yahoo.com>
    Re: Putting a line in a specific place in a file <bryan@worldspice.net>
        simple regular expression <olaf@yahoo.es>
    Re: simple regular expression <someone@example.com>
    Re: simple regular expression <olaf@yahoo.es>
    Re: simple regular expression <rvtol+news@isolution.nl>
    Re: simple regular expression <someone@example.com>
    Re: simple regular expression <rvtol+news@isolution.nl>
        SUID script?? <richardrothwell@gmail.com>
        Using Perl to join lines in a file <ningli2000@hotmail.com>
    Re: Using Perl to join lines in a file <someone@example.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 07 Nov 2006 13:41:00 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: $var=...
Message-Id: <eiq07a$kjn$1@mlucom4.urz.uni-halle.de>

Olaf wrote:
> $var=<STDIN>; chomp($var); if (($var =~ /^./) = ($var =~ /.$/ )) {}

The closest thing to your trial would be
probably sth. like this (as others have already said):

    chomp( my $var=<STDIN> );

    if( $var =~ /^(.).*?\1$/ ) {
       print "thats it\n"
    }
    else {
       print "nope\n"
    }


JWK already posted a more general solution
with "\A ... \z" as the string boundaries, you
can - in many cases (find out wich) use the "^...$"
notation that you tried to apply above.

What you really search after is therefore:

^(.)  ==> start of line with one character following
       ==> capture this charachter as #1
 .*?   ==> find any (0 or more) characters until (?)
  \1   ==> ... the first captured character shows up
  $    ==> directly followed by a 'line end'


You could also find a solution (besides the substr thing)
by stating

  ...
  chomp( my $var=<STDIN> );
  print map{ $_->[0] eq $_->[-1] ? 'same':'differ'} [split '', $var];
  ...

Regards

Mirco



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

Date: Tue, 07 Nov 2006 12:40:38 +0100
From: Olaf <olaf@yahoo.es>
Subject: $var=<STDIN>; chomp($var); if (($var =~ /^./) = ($var =~ /.$/ )) {}
Message-Id: <eiprbn$jee$1@cormoran.emeteo.local>

$var=<STDIN>; chomp($var); if (($var =~ /^./) = ($var =~ /.$/ )) {}


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

Date: Tue, 07 Nov 2006 12:00:02 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: $var=<STDIN>; chomp($var); if (($var =~ /^./) = ($var =~ /.$/ )) {}
Message-Id: <6z_3h.58228$P7.46745@edtnps90>

Olaf wrote:
> $var=<STDIN>; chomp($var); if (($var =~ /^./) = ($var =~ /.$/ )) {}

$ perl -ce'$var=<STDIN>; chomp($var); if (($var =~ /^./) = ($var =~ /.$/ )) {}'
Can't modify pattern match (m//) in list assignment at -e line 1, near ")) "
-e had compilation errors.

Perhaps you meant:

if ( substr( $var, -1 ) eq substr( $var, 0, 1 ) ) {}



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Tue, 07 Nov 2006 12:32:13 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Data plotting questions   Nov. 2, 2006
Message-Id: <h1%3h.3404$L6.544@newsread3.news.pas.earthlink.net>

First I would like to thank all of the people who responded with helpful
suggestions for my Plot applications question.

It appears that the next step to take would be to download the latest
version of Perl from the ActiveState site.  And in that regard, I have the
following question:


I am presently using Perl version 5.8.3.809 from ActiveState with Windows
XP.  If I install the latest version, will that have any significant impact
on the Perl programs I have already developed?


For example, I make extensive use of the "GoTo" command.  That is probably
not the case for most people writing computer programs.  If the latest Perl
version has eliminated that command then that would have a significant
impact on my present computer programs.  Obviously, without seeing my
programs no one would actually be able to answer that question in detail.  I
am just looking for general information.

Finally, I see that ActiveState has versions of several other languages
available including Python and Tcl.  Without getting too technical, can
anyone explain how they differ from Perl?  I am primarily interested in a
versatile language which would be easy for scientists to use.  Perl is quite
versatile.  But I personally feel that you need a fair amount of programming
experience to make effective use of it.





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

Date: Tue, 07 Nov 2006 11:33:52 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help in regular expression
Message-Id: <Aa_3h.59672$H7.42844@edtnps82>

Kimi wrote:
> 
> I relatively new to perl and hence the regular expressions as well....
> 
> Can somebody help me understanding this re syntax, To be precise i need
> to know what and all pattern the below expression matches to
> 
>  if ($string =~ /^(ORA-[0-9]+):.*/ || $string =~ /.*[
> ]+(ORA-[0-9]+):.*/ || $string =~ /^(Corrupt block)/)

$string =~ /
           ^        # match at the beginning of $string
           (        # start capturing here
           ORA-     # match the literal string 'ORA-'
           [0-9]+   # match one or more of the character in the range 0-9
           )        # end capturing
           :        # match the literal string ':'
           .*       # match zero or more of any character (except newline)
           /x

$string =~ /
           .*       # match zero or more of any character (except newline)
           [ ]+     # match one or more space character
           (        # start capturing here
           ORA-     # match the literal string 'ORA-'
           [0-9]+   # match one or more of the character in the range 0-9
           )        # end capturing
           :        # match the literal string ':'
           .*       # match zero or more of any character (except newline)
           /x

$string =~ /
           ^               # match at the beginning of $string
           (               # start capturing here
           Corrupt block   # match the literal string 'Corrupt block'
           )               # end capturing
           /x


John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: 7 Nov 2006 03:40:44 -0800
From: "Kimi" <shafa.fahad@gmail.com>
Subject: Re: Help in regular expression
Message-Id: <1162899644.169908.162960@i42g2000cwa.googlegroups.com>


John W. Krahn wrote:
> Kimi wrote:
> >
> > I relatively new to perl and hence the regular expressions as well....
> >
> > Can somebody help me understanding this re syntax, To be precise i need
> > to know what and all pattern the below expression matches to
> >
> >  if ($string =~ /^(ORA-[0-9]+):.*/ || $string =~ /.*[
> > ]+(ORA-[0-9]+):.*/ || $string =~ /^(Corrupt block)/)
>
> $string =~ /
>            ^        # match at the beginning of $string
>            (        # start capturing here
>            ORA-     # match the literal string 'ORA-'
>            [0-9]+   # match one or more of the character in the range 0-9
>            )        # end capturing
>            :        # match the literal string ':'
>            .*       # match zero or more of any character (except newline)
>            /x
>
> $string =~ /
>            .*       # match zero or more of any character (except newline)
>            [ ]+     # match one or more space character
>            (        # start capturing here
>            ORA-     # match the literal string 'ORA-'
>            [0-9]+   # match one or more of the character in the range 0-9
>            )        # end capturing
>            :        # match the literal string ':'
>            .*       # match zero or more of any character (except newline)
>            /x
>
> $string =~ /
>            ^               # match at the beginning of $string
>            (               # start capturing here
>            Corrupt block   # match the literal string 'Corrupt block'
>            )               # end capturing
>            /x
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order.       -- Larry Wall


Thanks John, That helped a lot....



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

Date: Tue, 7 Nov 2006 07:24:34 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Keep getting error with email validation script
Message-Id: <slrnel128i.bbs.tadmc@tadmc30.august.net>

grocery_stocker <cdalten@gmail.com> wrote:
> Tad McClellan wrote:
>> grocery_stocker <cdalten@gmail.com> wrote:
>> >
>> > Tad McClellan wrote:
>> >> grocery_stocker <cdalten@gmail.com> wrote:
>> >>
>> >> > I
>> >> > also figures since the OP is & to invoke the subroutine,
>> >>
>> >>
>> >> What effect does using & on the function call have for the
>> >> function that is being discussed?
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> >
>> > I forgot. I think it was something to do with the fact the OP was
>> > already screwing himself using &..
>>
>>
>> How was using & screwing him up?
>>
>
> Here is
> the best thing my minimum wage mind can came up with in terms of having
> & screw himself. Say I modify the code such that:


If you modify the code, then you are answering a question from
the one that I posed.

I know full well the effect of using an ampersand on function calls,
but none of those effects are going to happen in the code you claimed
was "screwed". It does not use prototypes, and it does not call
functions with no argument list, so using an ampersand does NOT
screw anything up.

Claiming that using the ampersand is a problem for the OP is
simply leading him on a wild goose chase.


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


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

Date: Tue, 07 Nov 2006 07:45:51 -0600
From: Ken Browning <kenbrow@bellsouth.net>
Subject: Perl and XML Question
Message-Id: <4f31l2t53r2eta3b9jhrl2amp8moqtbhi5@4ax.com>

I have been working with Perl for a while now, but have not used it
with XML - I am an XML noob. 

 I want to be able to read an XML schema file and initialize an
instance of the data item specified in the XML schema file.  I then
would like to initialize the various "fields"  that make up theoverall
item.  Once I have all my data in order I will use "Post"
functionality (that part works already for me!) to send the item on
its way.  Any suggestions of the first part of the scenario I
describe?


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

Date: Tue, 07 Nov 2006 10:00:47 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Perl and XML Question
Message-Id: <4550adae$0$10308$815e3792@news.qwest.net>

Ken Browning wrote:

>  I want to be able to read an XML schema file and initialize an
> instance of the data item specified in the XML schema file.  
[...]
> Any suggestions of the first part of the scenario I
> describe?

Use CPAN and search for XML. http://search.cpan.org/ or simply use
your favorite Internet search engine and look for "perl xml". You
would have found many solutions on your own in a matter of minutes.


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

Date: 7 Nov 2006 07:46:21 -0800
From: "prattm@gmail.com" <prattm@gmail.com>
Subject: Re: Perl with setuid enabled
Message-Id: <1162914380.932219.78730@m7g2000cwm.googlegroups.com>

Dan,

I tried several variations of your idea below but never could get the
correct version to run (it kept defaulting to 5.003 in /usr/bin,
whereas I'd it to use 5.8.6 that we built ourselves).  What's weird is
I can do it on the command line just fine:

> /usr/bin/env ${PERL} -v

It prints out 5.8.6, no problem.  But when I throw this in a file and
try to execute it, it gives me "/usr/bin/env: Directory or file not
found" (with exit code 127, meaning it cannot find whatever $PERL is
pointing to).

The good news is, /usr/bin/perl is current enough to let script do what
it needs (as far as running in taint mode), but it would still be nice
to use to most recent version we have built.

Thanks for the input,

Mike


Dan Mercer wrote:
> <prattm@gmail.com> wrote in message news:1162834627.465053.100680@k70g2000cwa.googlegroups.com...
> : We have a bunch of Perl scripts on our system, all of which use the
> : following header:
> :
> : #!/bin/ksh -- # -*- perl -*-
> : eval 'exec ${PERL} $0 ${1+"$@"}'
> :   if 0;
> :
> : The idea is we maintain a common variable $PERL that points to our
> : latest version.  This works fine and dandy, but one particular script
> : is running with setuid enabled (4110 permission) and has problems with
> : this header.  It prints out the message:
> :
> : Unrecognized character \x7F at /bin/ksh line 1.
> :
> : The character 7F is the "delete" character, but I copied and pasted the
> : ksh header from another script that works, so I don't believe there is
> : any hidden character(s).  We've also tried something like:
> :
> : #!${PERL}
> :
> : but that didn't work. The only way to get it to work is to hardcode the
> : path to perl executable, but this requires more maintenance when
> : upgrading our version of perl and we'd like to avoid it if possible.
> : Anyone have any ideas?
> :
> : Thanks, Mike
> :
>
> use env
>
> #!/usr/bin/env perl
> use warnings;
> use strict;
> ...
> 
> Dan Mercer



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

Date: 07 Nov 2006 14:47:28 GMT
From: xhoster@gmail.com
Subject: Re: process subregions on an image/matrix
Message-Id: <20061107094844.401$nV@newsreader.com>

"alexxx.magni@gmail.com" <alexxx.magni@gmail.com> wrote:
> Hi everybody, I need a bit of help on the programming side:
>
> I'm trying to write a program to perform a filtering operation on an
> image,
> represented as a matrix of integers.
> So I'm 1st thing writing a procedure that scans the image, and, when
> finding a pixel in the color to be processed, it scans all the
> neighboring pixels until all the cluster is processed (and, if its size
> is in the correct range, it applies the transform).
>
> Right now I perform this scanning of the cluster in the way I find most
> elegant: recursion:
>
> sub recurseinto
> {
>     my ($x,$y)=@_;
>     my $c;
>
>     $flag[$x][$y]=1;
>     $c=1;
>
>     if (($x-1>0)&&($flag[$x-1][$y]==0)&&($img[$x-1][$y]==$col)) { $c +=
> recurseinto($x-1,$y) }
>     if (($x+1<=$width)&&($flag[$x+1][$y]==0)&&($img[$x+1][$y]==$col)) {
> $c += recurseinto($x+1,$y) }
>     if (($y-1>0)&&($flag[$x][$y-1]==0)&&($img[$x][$y-1]==$col)) { $c +=
> recurseinto($x,$y-1) }
>     if (($y+1<=$height)&&($flag[$x][$y+1]==0)&&($img[$x][$y+1]==$col))
> { $c += recurseinto($x,$y+1) }
>     return $c;
>
> }
>
> Well, it works, but - I hate to admit it - it's slow.
>
> The question is: in which other way you would perform this task?

You could use traditional methods to remove recursion using a stack.

my @stack = (@_); #starting point
#....
while (@stack) {
  my ($x,$y)=splice @stack,0,2;
  if whatever($x-1,$y) { push @stack, $x-1,$y; $c++};
  if whatever($x+1,$y) { push @stack, $x+1,$y; $c++};
  # etc.
}

But if you need it to be hugely faster, I'd look into switching languages,
either to C (Inline::C) or some specialized image processing language.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 7 Nov 2006 04:29:44 -0800
From: "samasama" <bryan@worldspice.net>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <1162902583.949929.212250@m7g2000cwm.googlegroups.com>

 Yeah, got all this... Just trying to understand the line that John
threw down...
( $. == $gpg_line .. /exclude\=.*/i ) =~ /E/
Which he demonstrated the same method piping seq to perl above...
Though, I think that I only confused me more : ) 


--
samasama



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

Date: Tue, 07 Nov 2006 08:41:44 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <12l16p07a00m20f@news.supernews.com>

samasama wrote:
>  Yeah, got all this... Just trying to understand the line that John
> threw down...
> ( $. == $gpg_line .. /exclude\=.*/i ) =~ /E/
> Which he demonstrated the same method piping seq to perl above...
> Though, I think that I only confused me more : ) 
> 
> 
> --
> samasama
> 

See if this helps you get started ....

The .. operator will test the right operand on the same iteration that 
the left operand flips the operator into the true state.

while (<>) {
    if (/BEGIN PATTERN/ .. /END PATTERN/) {
       # line falls between BEGIN and END in the
       # text, inclusive.
    }
}


while (<>) {
    if (FIRST_LINE_NUM .. LAST_LINE_NUM) {
       # operate only between first and last line, inclusive.
    }
}

-- 

Len


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

Date: 7 Nov 2006 07:29:06 -0800
From: "samasama" <bryan@worldspice.net>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <1162913346.764378.68790@f16g2000cwb.googlegroups.com>



> while (<>) {
>     if (/BEGIN PATTERN/ .. /END PATTERN/) {
>        # line falls between BEGIN and END in the
>        # text, inclusive.
>     }
> }
>
>
> while (<>) {
>     if (FIRST_LINE_NUM .. LAST_LINE_NUM) {
>        # operate only between first and last line, inclusive.
>     }
> }
>

 That did help, but what about the =~ /E/ ?
I tried finding ref to that in perlre but couldn't... ?

Thanks a lot

--
samasama



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

Date: Tue, 07 Nov 2006 12:13:17 +0100
From: Olaf <olaf@yahoo.es>
Subject: simple regular expression
Message-Id: <eippoe$gai$1@cormoran.emeteo.local>

Which is the simplest way to know if a $var start and finish with the 
same character?


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

Date: Tue, 07 Nov 2006 11:20:57 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: simple regular expression
Message-Id: <t_Z3h.57943$P7.10465@edtnps90>

Olaf wrote:
> Which is the simplest way to know if a $var start and finish with the
> same character?

$var =~ /\A(.).*\1\z/s;


John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Tue, 07 Nov 2006 12:33:13 +0100
From: Olaf <olaf@yahoo.es>
Subject: Re: simple regular expression
Message-Id: <eipqts$iod$1@cormoran.emeteo.local>

John W. Krahn wrote:
> 
> $var =~ /\A(.).*\1\z/s;
> 

Ok, but I don't understand. I need to learn more about regular exp.
I suppose that the answer would be possible, comparing first and last 
with ^ and $.








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

Date: Tue, 7 Nov 2006 13:33:29 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: simple regular expression
Message-Id: <eiq228.1gk.1@news.isolution.nl>

Olaf schreef:
> John W. Krahn:


>> [head eq tail]
>> $var =~ /\A(.).*\1\z/s;
>
> Ok, but I don't understand. I need to learn more about regular exp.
> I suppose that the answer would be possible, comparing first and last
> with ^ and $.

Read perlretut and perlre.
Hint-1: If your $var can contain newlines, you need to use "\A" in stead
of "^".
Hint-2: See the s-modifier.


Alternative, using "^" and "$" anchors:

   $c   = qr/.|\n/ ;
   $var =~ /^($c)$c*\1$/ ;

Alternative for $c:

   $c   = qr/./s ;

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Tue, 07 Nov 2006 12:48:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: simple regular expression
Message-Id: <zg%3h.58586$P7.16859@edtnps90>

Dr.Ruud wrote:
> Olaf schreef:
>>John W. Krahn:
> 
> 
>>>[head eq tail]
>>>$var =~ /\A(.).*\1\z/s;
>>Ok, but I don't understand. I need to learn more about regular exp.
>>I suppose that the answer would be possible, comparing first and last
>>with ^ and $.
> 
> Read perlretut and perlre.
> Hint-1: If your $var can contain newlines, you need to use "\A" in stead
> of "^".

Without the /m modifier \A and ^ are exactly the same.


John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Tue, 7 Nov 2006 14:33:34 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: simple regular expression
Message-Id: <eiq5oc.16s.1@news.isolution.nl>

John W. Krahn schreef:
> Dr.Ruud:
>> Olaf:
>>> John W. Krahn:

>>>> [head eq tail]
>>>> $var =~ /\A(.).*\1\z/s;
>>>
>>> Ok, but I don't understand. I need to learn more about regular exp.
>>> I suppose that the answer would be possible, comparing first and
>>> last with ^ and $.
>> 
>> Read perlretut and perlre.
>> Hint-1: If your $var can contain newlines, you need to use "\A" in
>> stead of "^".
> 
> Without the /m modifier \A and ^ are exactly the same.

Aaargh, thanks for the correction.

The /s modifier makes "." also match a newline. 
The /m modifier makes "^"/"$" match start/end of any embedded line.

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: 7 Nov 2006 07:56:34 -0800
From: "richardrothwell@gmail.com" <richardrothwell@gmail.com>
Subject: SUID script??
Message-Id: <1162914994.420364.47030@b28g2000cwb.googlegroups.com>

I have a C program that runs as an SUID script. But I need to extend
this script to query a database first and I've since found out that
this cannot be done.

So I was wondering if Perl can be used to create an SUID script or will
Linux not run it??



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

Date: 7 Nov 2006 06:53:59 -0800
From: "nickli" <ningli2000@hotmail.com>
Subject: Using Perl to join lines in a file
Message-Id: <1162911239.040677.176330@m7g2000cwm.googlegroups.com>

Hi,

   I have a file with 100 lines each with one record on each line. The
file is as follows:

86274886
81459795
78113464
87882848
78286396
77618550
84180945
74310227
69806585
74111006
80947497
80404769
80377684
80259589
68195927
67187136
67345008
78745575
77970192
77937896
85872999
85954776
85930231
85927774
85887197
85911310
85577810
85645926
85645257
85609385
85428783
85455622
86143491
86143435
85501684
86168358
86143964
86036286
85830781
86159082
98624907
98484232
98506935
21986088
103299004
101901712
21246519
69548444
69534265
98523400
51579566
63869631
47500761
63974605
63727180
48348160
51465556
51468035
50245797
49894334
90940723
16226272
16222857
16215465
16199374
16184704
16355800
16320328
54274394
54210417
79781445
79778999
79772052
79720217
79719727
80117560
80102759
80152647
80116881
79976145
19592974
19587585
19585909
19574981
19574860
19574560
19659755
19654534
19636650
19630077
17823273
17817739
17764284
17728035
17694825
17766363
17730554
17675729
17803920
17773924

     I would like to put 5 records on a line, separated by commas, with
a total of 20 lines:

        ,86274886,81459795,78113464,87882848,78286396
        ,80947497,80404769,80377684,80259589,68195927
         ......................................
         ......................................

     I can do this with shell script using split and paste commands. I
would like to ask for help as I am new to Perl.

     Thanks in advance.

     Nick Li



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

Date: Tue, 07 Nov 2006 15:10:08 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Using Perl to join lines in a file
Message-Id: <kl14h.96347$E67.74421@clgrps13>

nickli wrote:
> 
>    I have a file with 100 lines each with one record on each line. The
> file is as follows:
> 
> 86274886
> 81459795
> 78113464

[ snip ]

> 17675729
> 17803920
> 17773924
> 
>      I would like to put 5 records on a line, separated by commas, with
> a total of 20 lines:
> 
>         ,86274886,81459795,78113464,87882848,78286396
>         ,80947497,80404769,80377684,80259589,68195927
>          ......................................
>          ......................................

perl -lpe'$\=$.%5?",":$/' yourfile



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: 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 9938
***************************************


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