[23911] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6113 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 11 11:05:39 2004

Date: Wed, 11 Feb 2004 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           Wed, 11 Feb 2004     Volume: 10 Number: 6113

Today's topics:
    Re: a2p (Scottie)
    Re: Anyone using Berkley XML DB w/Perl (of course)...? <usenet@morrow.me.uk>
    Re: Array size <remorse@partners.org>
        Broken Pipe (Jon Landenburer)
    Re: Broken Pipe <kasp@epatra.com>
    Re: generate a list of file extensions? <bik.mido@tiscalinet.it>
    Re: How to call a perl script that returns nothing in a <usenet@morrow.me.uk>
    Re: How to call a perl script that returns nothing in a <jurgenex@hotmail.com>
    Re: How to call a perl script that returns nothing in a <noreply@gunnar.cc>
        Just curious: perl + C + asm, any? <bik.mido@tiscalinet.it>
    Re: Launching an .exe (Jon Landenburer)
    Re: Perl usage these days? (Caj Zell)
        perl/korn scirpt for appending first variable to end of (NNTP)
    Re: perl/korn scirpt for appending first variable to en <jwillmore@remove.adelphia.net>
    Re: perl/korn scirpt for appending first variable to en <noreply@gunnar.cc>
    Re: perl/korn scirpt for appending first variable to en <tony.walton@s_u_n.com>
    Re: perl/korn scirpt for appending first variable to en <beardy@beardy.net>
    Re: perl/korn scirpt for appending first variable to en <barmar@alum.mit.edu>
    Re: perl/korn scirpt for appending first variable to en <barmar@alum.mit.edu>
    Re: perl/korn scirpt for appending first variable to en <tony.walton@s_u_n.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 11 Feb 2004 08:01:30 -0800
From: Scott_Starker@sil.org (Scottie)
Subject: Re: a2p
Message-Id: <899d28b2.0402110801.63822f83@posting.google.com>

Ben,

Thanks. I just wanted to find out how someone would, in awk, use
"getline", etc. and convert it into Perl. Something pretty simple like
that.
 
> > Where can I find the a2p?
> 
> ...you can get perl for windows from activestate.com. a2p is included.

Thanks again.

Scottie


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

Date: Wed, 11 Feb 2004 15:49:00 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Anyone using Berkley XML DB w/Perl (of course)...?
Message-Id: <c0ditc$oe3$1@wisteria.csv.warwick.ac.uk>


"Paul Marquess" <paul.marquess@btinternet.com> wrote:
> "Ben Morrow" <usenet@morrow.me.uk> wrote in message
> news:c0ap5d$95u$1@wisteria.csv.warwick.ac.uk...
> > Yes, but you don't need to give them the same names as the C++ classes
> > had.
> 
> I assume your issue isn't really that I've used the same names as the C++
> classes, but that I've put them in a top-level namespace?

Of course.

> Ignoring namespace issues for a moment, reusing the C++ class names
> seems to make perfect sense.

Well, yes... it depends on who's point of view your coming from. There
are rather different conventions for how things should be named in C++
and Perl (in particular, XML-related and DB-related modules in Perl
*always* spell them XML and DB rather than Xml and Db), so none of
those names would have been invented by someone writing a DBXML
library from scratch in Perl. If you are more concerned that someone
with familiarity with this library in C++ should not be lost when
using it in Perl, then stick to the C++ names. If you are more
concerned that someone used to Perl should not be confused when coming
to this module as a Perl module, with no knowledge of or interest in
the underlying C++ library, then more Perlish names would be better.

> > What happens if someone's using another XML module as well (not
> > at all unlikely), and that happened to also define the package
> > XmlDocument?
> >
> > Indeed, the C++ classes are all in the namespace DbXml, which will
> > keep them from conflicting with any other XmlDocument class people
> > might be using. I would have given the classes names like
> > DB::XML::Container, and kept all the names below DB::XML, or
> > something.
> 
> There is always a problem of clashing namespaces, and I accept that by using
> quite a few top-level names I'm increasing that possibility.

The point of the CPAN namespace-registration system is that it gets
rid of the problem. People register their namespaces, and stay within
them, and then we don't get conflicts. You will note that the PAUSE
module-list registration form specifically says that you must provide
good reasons why you need a new top-level namespace.

> I'm not convinced it's as big a problem as you make out,

Are you not? I think that as things stand there may not be much of a
problem, because 1. noone else would use those C++ish names and
2. everyone else will follow the rules and not use top-level names
when they don't need to. I don't think these are good things to rely
on.

As I said, consider someone using some other XML module: say, to get
XML out of their database and insert it into some other system. If the
name XmlDocument were considered fair game, you must admit it's not at
all unlikely that this other module author would have used it as
well. The only way there is any chance of avoiding clashes is if
everyone sticks within their own namespace.

> but I'll have a think about this
> one - my preferred choice would be to go for DbXml:: as the common prefix
> for all the class names.

OK... it doesn't matter what you choose, as long as you choose something.

> > The whole exception-handling logic seems unnecessarily
> > complex: what's wrong with
> >
> >     package DB::XML::Exception;
> >
> >     our @EXPORT = qw/catch/;
> >
> >     sub catch {
> >         my $type = shift;
> >         UNIVERSAL::isa($@, __PACKAGE__) and $@->{type} eq $type
> >             and return $@;
> >         return;
> >     }
> >
> >     package main;
> >
> >     eval {
> >         ...
> >     }
> >     if (my $e = catch 'DbException') {
> >         ...
> >     }
> 
> Ignoring the hoops I may have jumped through to implement my version of
> "catch",  from an end users point of view, that looks very like what I've
> already implemented.

That was the point: it's almost identical, and doesn't stomp on about
6 top-level names.

> One thing on my todo list is to provide a shortcut to get at the exception
> string. I'll probably do it by overloading the stringification operator.
> 
>      eval {
>          ...
>      };
> 
>      if (my $e = catch XmlException) {
>          print "got this exception $e\n";
>      }

Oh, does it not already?... I'd kinda assumed it would :).

> > or
> >
> >     if (ref $@ and $a->isa(DB::XML::X::DbDeadlock)) {
> 
> Personally, I hate that syntax in user code, although it should
> already work with my current interface. :-)

Yeah, but it's (one of) the Perl idiom(s) for exception
catching. Someone reading that code will see instantly what it
does. Inventing random new interfaces violates the principle of least
surprise.

> > or even
> >
> >     if ($@ and $!{EDEADLK}) {
> >
> > , which I at least find much more Perlish? The mapping seems pretty
> > clear:
> >
> > DbDeadlockException          EDEADLK
> > DbException                  is never thrown
> > DbLockNotGrantedException    EWOULDBLOCK
> > DbRunRecoveryException       EINVAL
> >
> > etc. XmlException could probably just throw a string.
> 
> If I was going to go down that route, I'd rip out the exception handling
> interface and use return codes instead.

Yup.... personally, I'd not object to that. Remember, people can
always put it back with use fatal. One of the things I dislike about
Java (I've never written any (modern) C++) is that everything has to
be wrapped in a try/catch block.

> > > > And is it really necessary to have the interface be so C++ish?
> > >
> > > Well it is an interface to a C++ library after all  :-)
> >
> > True... your BerkeleyDB module, though, provides a much more Perl-ish
> > interface to the C db libraries.
> 
> I think there are a couple of  reasons for the difference in the interfaces
> I created. The first is simply down to the fact that the native dbxml
> interface is C++, while Berkeley DB is C.

 ...yes...? Neither is Perl, despite the superficial similarities
between C++'s and Perl's OO.

> The other reason I've deliberately kept close to the C++ interface was to
> future proof myself. The dbxml library is still quite young and has already
> changed a couple of times --  I don't want to paint myself into any corner
> with interface decisions.

This is, of course, sensible. Might I respectfully suggest a strategy
of having a DbXml::Native module that is just a very thin XS wrapper
around the C++ library, and then making DbXml implemented in Perl on
top of that?

Ben

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


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

Date: Wed, 11 Feb 2004 10:27:56 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: Array size
Message-Id: <remorse-624040.10275611022004@plato.harvard.edu>

In article <m23c9i5ven.fsf@gw.dd-b.net>,
 David Dyer-Bennet <dd-b@dd-b.net> wrote:

> Richard Morse <remorse@partners.org> writes:
> > $ perldoc perlintro
> 
> etc.  Yes, I know there's doc on $#arrayname; plenty of it.  It was
> trying to apply it to a reference that I asked about, and was
> talking.  It's really better to understand the discussion before
> jumping into the middle!

Mea culpa.


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

Date: 11 Feb 2004 07:05:13 -0800
From: jon.m.landenburger@verizon.com (Jon Landenburer)
Subject: Broken Pipe
Message-Id: <feee7535.0402110705.3d9756c1@posting.google.com>

We have these large files which are compressed. I need to read the
first 50 lines and make various calcs. In sh I been doing
zcat dog.Z |head -n50 > dog.dat
In perl I been gettuing broken pipes.  I get all of the data but I get
a message (stderr)
  dog: Broken pipe 

to isolate the probelm I wrote
      @temp = `zcat $filename | head -n50|`;
        print @temp;
        print "wait\n"; $C=  <STDIN>;

it will sit for about 30 seconds then give that message .
I will get similar results if I do

     open (scnfile, "zcat dog.z|") or die...
     while ($line = <scnfile>) {
        if ($i++ > 50 ) {last;}
     }
    print "wait\n"; $C=  <STDIN>;

same thing happens.  a pause of 30 secs then the message     dog:
broken pipe


Why and where I dont know.
Any ideas?




In perl I been did 
      open (scnfile, "zcat dog.Z |head -n50 |") or die ....
      while ($line = <scnfile>){
          .......
       }
       close file;
get next file ......

when I do this it completes the first file, shows the calce but then
displays a message (stderr)
  dog: Broken pipe 

so then I replaced the open ,read,close with a simpler
    @lines = `zcat dog.Z |head -n50 `;
and still get the same thing.
Its a harmless thing but worrysome.
the zcat in sh gives no broken pipe


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

Date: Wed, 11 Feb 2004 15:26:07 -0000
From: "Kasp" <kasp@epatra.com>
Subject: Re: Broken Pipe
Message-Id: <c0dhg5$tkd$1@newsreader.mailgate.org>

For @temp = `zcat $filename | head -n50|`;
 .....Why is there a pipe after head command?







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

Date: 11 Feb 2004 14:44:26 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: generate a list of file extensions?
Message-Id: <654n20tog7epklp39c7nuf548r94j35uog@4ax.com>

On Tue, 10 Feb 2004 14:43:49 -0800,
"davido@codethought.nospamforme.com" <me@privacy.net> wrote:

>I need to scan a directory tree and generate a list of file extensions
>from that tree for a search against a database.  That way I can be
>sure the database is properly updated based on all of the extensions
>in this directory.  The directory amounts to projects code and binary
>files.  I know how to use File::Find to search a list of file types
>and get their *names*.  Would searching and getting the file types be
>basically the same thing?
>
>Could someone point me at some code that could help me accomplish
>this?  Much appreciated.

Sorry to say this, but it may be that Perl is not strictly necessary
for this task, and neither convenient. Even if I use Perl to do almost
everything[*], when I need to get a list of all file extensions in a
directory tree I simply issue:

  find whatever/ -type f | sed 's/.*\.//' | sort | uniq

If you want a Perl only solution, others have given you good hints,
and of course it quickly becomes necessary when there are enough other
details you must take care of.


[*]As I said in another thread some time ago, even to do simple sums
and other calculations, instead of using bc or bash's own features.


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Wed, 11 Feb 2004 14:59:32 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How to call a perl script that returns nothing in an HTML
Message-Id: <c0dg0k$lnq$1@wisteria.csv.warwick.ac.uk>


Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Gunnar Hjalmarsson wrote:
> > 
> >     print "Content-type: image/gif\n\n";
> >     open IMG, '< /path/to/blank.gif' or die "Couldn't open image $!";
> >     print while <IMG>;
> 
> Should better be:
> 
>      print "Content-type: image/gif\n\n";
>      open IMG, '< /path/to/blank.gif' or die "Couldn't open image $!";
>      binmode IMG;

binmode STDOUT;
$/ = \4096; # or some such: no point reading a binary file by lines

>      print while <IMG>;

Or use IO::SendFile (if you can).

Ben

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


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

Date: Wed, 11 Feb 2004 15:02:03 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to call a perl script that returns nothing in an HTML
Message-Id: <LtrWb.4696$1B6.1911@nwrddc03.gnilink.net>

"Danny" <dannywork5@hotmail.com> wrote:
> Thanks for the help with this command:
>
> print "Status: 204 No Content\n\n";
> which returns nothing in a perl script.

I guess you have a somewhat unusual definition of "return".
If you are talking about "the command doesn't produce any output" then you
are wrong. Obviously print() prints something.
If you are talking about the return value of the print statement then you
are wrong again:
    print   [...] Returns true if successful.
If you are talking about the return value of the program then, well, you are
right. If you want that then you need to use the exit() command.

So, what "return" are you talking about?

> This is great because I just want my perl script to increment a counter
> and put result in a text file which it does fine how.

Ok, then I guess you don't have a Perl problem.

> But now how do I call this from an .html?  I used to call it like
> this
> <img src="path to cgi script">

Ahhh, ok, this is a disguised CGI question.
Please see "perldoc -q 500" (althought that answer seems to address a
different problem it applies to your question, too.)

jue




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

Date: Wed, 11 Feb 2004 16:27:48 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to call a perl script that returns nothing in an HTML
Message-Id: <c0dhr1$13ehr4$1@ID-184292.news.uni-berlin.de>

Ben Morrow wrote:
> Gunnar Hjalmarsson wrote:
>>
>>     print "Content-type: image/gif\n\n";
>>     open IMG, '< /path/to/blank.gif' or die "Couldn't open image $!";
>>     binmode IMG;
> 
> binmode STDOUT;

Ouch! Still missed that. Thanks!

> $/ = \4096; # or some such: no point reading a binary file by lines

Well, in this case we are probably talking about a 1px x 1px image.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 11 Feb 2004 14:44:27 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Just curious: perl + C + asm, any?
Message-Id: <9s3n205furb165kosic3blkk7crejmde1o@4ax.com>

As of the subject, I was wondering if anyone has ever written a binary
module for perl that in turn had some routines written in assembler,
for efficiency reasons.


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: 11 Feb 2004 08:03:33 -0800
From: jon.m.landenburger@verizon.com (Jon Landenburer)
Subject: Re: Launching an .exe
Message-Id: <feee7535.0402110803.790438a4@posting.google.com>

lmm <> wrote in message news:<m4ci209406brvbbohqjur3shto1q3mnrnv@4ax.com>...
> I have written a script that that is supposed write a host file, open
> a Windows executable file, sends out a few pings and then runs a batch
> file that maps drives.
> 
> The problem I am having is that the the script stops after the
> executable is launched.  Presumably because it does not  close and
> therefore the script "hangs."  The .exe is a VPN client so it cannot
> run last.  When I decided to add the pings and the batch file the
> script stopped working, of course now I realize it was never working
> as expected.
> 
> I have tried the following code to launch the exe:
> 
> my $exe = '"C:/Program Files/SonicWALL/SonicWALL Global VPN
> Client/SWGVpnClient.exe"' ;
> exec $exe ;
> 
> 

exec terminates replaces the current process with the one you are
calling.  There is no place to come back to.
use system("sdfsdfsdfsd");


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

Date: 11 Feb 2004 07:17:19 -0800
From: cajzell@hotmail.com (Caj Zell)
Subject: Re: Perl usage these days?
Message-Id: <c9eae90e.0402110717.36a4e879@posting.google.com>

thumb_42@yahoo.com wrote in message news:<8s4Wb.270436$xy6.1380339@attbi_s02>...
> Just a curious question:
> 
> What is perl being used for these days?

I am a developer of signal processing algorithms, mainly for video
compression and processing. This work is very focused on embedded
systems and all running code is therefore in assembly and c. However,
all system configuration, testing and reporting is implemented in
Perl. So, this is very far from web applications and Perl has
definitely found usage here. And it is cool.

Caj Zell


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

Date: 11 Feb 2004 06:32:41 -0800
From: news8080@yahoo.com (NNTP)
Subject: perl/korn scirpt for appending first variable to end of line.
Message-Id: <110fc16.0402110632.3a4203b0@posting.google.com>

I am writting a script that does some analysis of a log file and here
is what I need.

I need to take the first variable of the line, cut it and paste it to
the end of the line.

example:
input : accept blah blah blahc blah data data data 
output : blah blah blahc blah data data data accept

no. of variables very and thats why I can't use a simple script like
the following.

cat file | awk '{print $2,$3,$4,$5,$6,$7,$8,$1}' 

any ideas?


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

Date: Wed, 11 Feb 2004 09:42:08 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <pan.2004.02.11.14.42.06.957554@remove.adelphia.net>

On Wed, 11 Feb 2004 06:32:41 -0800, NNTP wrote:

> I am writting a script that does some analysis of a log file and here
> is what I need.
> 
> I need to take the first variable of the line, cut it and paste it to
> the end of the line.
> 
> example:
> input : accept blah blah blahc blah data data data 
> output : blah blah blahc blah data data data accept
> 
> no. of variables very and thats why I can't use a simple script like
> the following.
> 
> cat file | awk '{print $2,$3,$4,$5,$6,$7,$8,$1}' 
> 
> any ideas?

Many :-)

You could a few functions to do this.  Have a look at:
perldoc -f split
perldoc -f unpack
perldoc perlre

It depends on what you know about the data being parsed, how consistent
the data is, and how much work you really want to put into it.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
"I went to the museum where they had all the heads and arms from 
the statues that are in all the other museums."   -- Steven
<Wright 


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

Date: Wed, 11 Feb 2004 15:55:59 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <c0dfv5$15gdkq$1@ID-184292.news.uni-berlin.de>

NNTP wrote:
> I need to take the first variable of the line, cut it and paste it
> to the end of the line.
> 
> example:
> input : accept blah blah blahc blah data data data
> output : blah blah blahc blah data data data accept

If the "variables" are space separated, in Perl you can do:

     $_ = 'accept blah blah blahc blah data data data';
     my @vars = split;
     push @vars, shift @vars;
     my $newline = join ' ', @vars;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 11 Feb 2004 14:45:52 +0000
From: Tony Walton <tony.walton@s_u_n.com>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <402A4020.2060605@s_u_n.com>

NNTP wrote:
> I am writting a script that does some analysis of a log file and here
> is what I need.
> 
> I need to take the first variable of the line, cut it and paste it to
> the end of the line.


The clue's in the question.  cut and paste.

#!/bin/ksh
paste -d' ' <(cut -d' ' -f2- infile) <(cut -d' ' -f1 infile) > outfile

Quick and dirty.

-- 
Tony



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

Date: Wed, 11 Feb 2004 15:18:01 +0000
From: Beardy <beardy@beardy.net>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <0LrWb.2602$Y%6.387762@wards.force9.net>

Tony Walton wrote:
> NNTP wrote:
> 
>> I am writting a script that does some analysis of a log file and here
>> is what I need.
>>
>> I need to take the first variable of the line, cut it and paste it to
>> the end of the line.
> 
> 
> 
> The clue's in the question.  cut and paste.
> 
> #!/bin/ksh
> paste -d' ' <(cut -d' ' -f2- infile) <(cut -d' ' -f1 infile) > outfile
> 
> Quick and dirty.
> 

Tony, you certainly seem to have acquired a penchant for the "... <(...) 
 ..." construct :-)

I prefer:

cat infile | sed -e 's/^\([^ ]*\).\(.*\)$/\2 \1/' > outfile

Far more legible ;-)



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

Date: Wed, 11 Feb 2004 10:24:31 -0500
From: Barry Margolin <barmar@alum.mit.edu>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <barmar-7D8F25.10243111022004@comcast.ash.giganews.com>

In article <110fc16.0402110632.3a4203b0@posting.google.com>,
 news8080@yahoo.com (NNTP) wrote:

> I am writting a script that does some analysis of a log file and here
> is what I need.
> 
> I need to take the first variable of the line, cut it and paste it to
> the end of the line.
> 
> example:
> input : accept blah blah blahc blah data data data 
> output : blah blah blahc blah data data data accept
> 
> no. of variables very and thats why I can't use a simple script like
> the following.
> 
> cat file | awk '{print $2,$3,$4,$5,$6,$7,$8,$1}' 
> 
> any ideas?

awk '{first=$1; $1=""; print $0, first}' file

sed 's/^\([^ ]*\) \(.*\)$/\2 \1/' file

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

Date: Wed, 11 Feb 2004 10:49:15 -0500
From: Barry Margolin <barmar@alum.mit.edu>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <barmar-F16D66.10491511022004@comcast.ash.giganews.com>

In article <c0dfv5$15gdkq$1@ID-184292.news.uni-berlin.de>,
 Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:

> NNTP wrote:
> > I need to take the first variable of the line, cut it and paste it
> > to the end of the line.
> > 
> > example:
> > input : accept blah blah blahc blah data data data
> > output : blah blah blahc blah data data data accept
> 
> If the "variables" are space separated, in Perl you can do:
> 
>      $_ = 'accept blah blah blahc blah data data data';
>      my @vars = split;
>      push @vars, shift @vars;
>      my $newline = join ' ', @vars;

You don't even need the join; just do:

print "@vars\n";

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

Date: Wed, 11 Feb 2004 15:42:37 +0000
From: Tony Walton <tony.walton@s_u_n.com>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <402A4D6D.1090305@s_u_n.com>

Beardy wrote:
> Tony Walton wrote:
> 
>> NNTP wrote:
>>
>>> I am writting a script that does some analysis of a log file and here
>>> is what I need.
>>>
>>> I need to take the first variable of the line, cut it and paste it to
>>> the end of the line.
>>
>>
>>
>>
>> The clue's in the question.  cut and paste.
>>
>> #!/bin/ksh
>> paste -d' ' <(cut -d' ' -f2- infile) <(cut -d' ' -f1 infile) > outfile
>>
>> Quick and dirty.
>>
> 
> Tony, you certainly seem to have acquired a penchant for the "... <(...) 
> ..." construct :-)

I'm on commission from the manufacturers of "<", "(" and ")".


> 
> I prefer:
> 
> cat infile | sed -e 's/^\([^ ]*\).\(.*\)$/\2 \1/' > outfile
> 
> Far more legible ;-)

But using up most of the world's meagre supply of backslashes.

-- 
Tony





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

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


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