Re: a perl question

2011-01-06 Thread Matthew Seaman
On 05/01/2011 22:15, RW wrote:
 Personally I find that using cat makes things simpler and less error
 prone when reusing  pipelines in shell history.
 
 For example it's easier to edit 
 
  cat file | foo
 
 into 

  cat file | bar | foo
 or   cat file? | foo
 
 than editing 
 
  foo  file
 
 into
 
  bar  file | foo
 or   cat file? | foo

Little known factoid -- shell redirections can occur *anywhere* on the
command line.

%  foo cat
abcdefghijklmnopqrstuvwxyz
%  foo tr 'a-z' 'm-za-l'
mnopqrstuvwxyzabcdefghijkl

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW



signature.asc
Description: OpenPGP digital signature


Re: a perl question

2011-01-05 Thread Ian Smith
In freebsd-questions Digest, Vol 344, Issue 4, Message: 14
On Tue, 4 Jan 2011 23:24:01 -0700 Chad Perrin per...@apotheon.com wrote:
  On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr 
writes:
   
   Patrick cat asdf.txt | grep -v XYZ | grep -v bla
   
   And yet, you still have the Useless Use of Cat.
  
  The weirdest thing about most useless uses of cat is that not using cat
  would actually be a little clearer and involve fewer keystrokes -- as in
  this case.

Do you know of any 'less useless' or more economical way to do such as:

 % cat /boot/boot1 /boot/boot2 | diff - /boot/boot
 %

?, Ian
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-05 Thread Chip Camden
Quoth Chad Perrin on Tuesday, 04 January 2011:
 On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
   Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr 
   writes:
  
  Patrick cat asdf.txt | grep -v XYZ | grep -v bla
  
  And yet, you still have the Useless Use of Cat.
 
 The weirdest thing about most useless uses of cat is that not using cat
 would actually be a little clearer and involve fewer keystrokes -- as in
 this case.
 
 -- 
 Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


I blame OOP.  Programmer thinks about the data stream before they think
about the process.  It's a nouns-first orientation.

-- 
Sterling (Chip) Camden| sterl...@camdensoftware.com | 2048D/3A978E4F
http://camdensoftware.com | http://chipstips.com| http://chipsquips.com


pgpaYeod9JmjW.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread Chip Camden
Quoth Ian Smith on Thursday, 06 January 2011:
 In freebsd-questions Digest, Vol 344, Issue 4, Message: 14
 On Tue, 4 Jan 2011 23:24:01 -0700 Chad Perrin per...@apotheon.com wrote:
   On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
 Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr 
 writes:

Patrick cat asdf.txt | grep -v XYZ | grep -v bla

And yet, you still have the Useless Use of Cat.
   
   The weirdest thing about most useless uses of cat is that not using cat
   would actually be a little clearer and involve fewer keystrokes -- as in
   this case.
 
 Do you know of any 'less useless' or more economical way to do such as:
 
  % cat /boot/boot1 /boot/boot2 | diff - /boot/boot
  %
 
 ?, Ian
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

Here you're using cat for what it was intended -- conCATenation.  It's
the right tool for that job.

-- 
Sterling (Chip) Camden| sterl...@camdensoftware.com | 2048D/3A978E4F
http://camdensoftware.com | http://chipstips.com| http://chipsquips.com


pgp6YwaaNVSZJ.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread Chad Perrin
On Thu, Jan 06, 2011 at 12:07:13AM +1100, Ian Smith wrote:
 
 Do you know of any 'less useless' or more economical way to do such as:
 
  % cat /boot/boot1 /boot/boot2 | diff - /boot/boot
  %

Actually, that looks like a useful use of cat, whose original purpose it
is to concatenate the contents of two files.  `cat /boot/boot1
/boot/boot2` concatenates the contents of two files, so that the
resulting single text stream can be treated as a file to be compared by
diff to `/boot/boot`.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


pgpTrSURKXqIn.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread RW
On Wed, 5 Jan 2011 08:05:14 -0800
Chip Camden sterl...@camdensoftware.com wrote:

 Quoth Chad Perrin on Tuesday, 04 January 2011:

  The weirdest thing about most useless uses of cat is that not using
  cat would actually be a little clearer and involve fewer keystrokes
  -- as in this case.
  

 I blame OOP.  Programmer thinks about the data stream before they
 think about the process.  It's a nouns-first orientation.

You might easily get the same prejudice from data flow diagrams - or
plumbing. 

Personally I find that using cat makes things simpler and less error
prone when reusing  pipelines in shell history.

For example it's easier to edit 

 cat file | foo

into 
   
 cat file | bar | foo
or   cat file? | foo

than editing 

 foo  file

into

 bar  file | foo
or   cat file? | foo
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-05 Thread Chad Perrin
On Wed, Jan 05, 2011 at 10:15:38PM +, RW wrote:
 
 For example it's easier to edit 
 
  cat file | foo
 
 into 

  cat file | bar | foo
 or   cat file? | foo
 
 than editing 
 
  foo  file
 
 into
 
  bar  file | foo
 or   cat file? | foo

In this case, example was:

cat file | foo arg

. . . where it could have been:

foo arg file

That's just kind of absurd.  I mean, that sort of usage (foo arg file) is
exactly the purpose for which grep was designed.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


pgpuPZgJNS4Mz.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread RW
On Wed, 5 Jan 2011 15:13:02 -0700
Chad Perrin per...@apotheon.com wrote:


 In this case, example was:
 
 cat file | foo arg
 
 . . . where it could have been:
 
 foo arg file
 
 That's just kind of absurd.  I mean, that sort of usage (foo arg
 file) is exactly the purpose for which grep was designed.
 
Obviously, I'm talking about the general case. If I'd meant grep I'd
have written grep and not foo.  
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Peter Vereshagin
You know St. Peter won't call my name, freebsd-questions!
2011/01/04 02:32:00 -0800 S Mathias smathias1...@yahoo.com = To 
freebsd-questions@freebsd.org :

$ perl -Mstrict -nwe 'print unless m/bla|XYZ/;'  asdf.txt

73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB  12F8 0CE1 4AAC A0E2 6627)
--
http://vereshagin.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread krad
On 4 January 2011 10:32, S Mathias smathias1...@yahoo.com wrote:

 cat asdf.txt
 bla-bla
 bla-bla
 bla[XYZ]
 importantthing
 another important thing
 [/XYZ]
 bla-bla
 bla-bla
 [XYZ]
 yet another thing
 hello!
 [/XYZ]
 bla-bla
 etc.
 $ SOMEPERLMAGIC asdf.txt  output.txt
 $ cat output.txt
 importantthing
 another important thing
 yet another thing
 hello!


 how can i sovle this question? what is SOMEPERLMAGIC? are there any perl
 gurus, that have a little spare time?

 Thank you! :\



 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to 
 freebsd-questions-unsubscr...@freebsd.org



doesnt need to be perl either

cat asdf.txt | awk 'BEGIN {a=0} { if ( $0 ~ /\[XYZ\]/ ) a=1;  if ( $0 ~
/\[\/XYZ\]/ ) a=0; if ( a == 1) print $0}'

or something close to it
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Jonathan McKeown
On Tuesday 04 January 2011 12:32:00 S Mathias wrote:
 cat asdf.txt
 bla-bla
 bla-bla
 bla[XYZ]
 importantthing
 another important thing
 [/XYZ]
 bla-bla
 bla-bla
 [XYZ]
 yet another thing
 hello!
 [/XYZ]
 bla-bla
 etc.
 $ SOMEPERLMAGIC asdf.txt  output.txt
 $ cat output.txt
 importantthing
 another important thing
 yet another thing
 hello!

This could mean almost anything (witness another response which excludes lines 
containing blah or XYZ, which gives the desired output on your test input).

Are you actually trying to extract all the lines inside [XYZ]...[/XYZ] tags?

are the tags guaranteed not to occur on the lines you need to extract, as they 
appear here?

Because (all on one line)

perl -ne 'print if ($check = m{\[XYZ\]} .. m{\[/XYZ\]})  1 and 
$check !~ /E0$/' asdf.txt output.txt

produces the same output as you have above for the test input. (The .. range 
operator in scalar context is true as soon as the left-hand expression is 
true, and false as soon as the right-hand expression is true. It returns 1 
each time it becomes true, incrementing integers as it stays true, and 
appends E0 to the last number as it becomes false, which lets you exclude 
both endpoints).

Jonathan

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Patrick Bihan-Faou

Le 04/01/2011 14:06, krad a écrit :

On 4 January 2011 10:32, S Mathiassmathias1...@yahoo.com  wrote:


cat asdf.txt
bla-bla
bla-bla
bla[XYZ]
importantthing
another important thing
[/XYZ]
bla-bla
bla-bla
[XYZ]
yet another thing
hello!
[/XYZ]
bla-bla
etc.
$ SOMEPERLMAGIC asdf.txt  output.txt
$ cat output.txt
importantthing
another important thing
yet another thing
hello!


how can i sovle this question? what is SOMEPERLMAGIC? are there any perl
gurus, that have a little spare time?

Thank you! :\



___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to 
freebsd-questions-unsubscr...@freebsd.org



doesnt need to be perl either

cat asdf.txt | awk 'BEGIN {a=0} { if ( $0 ~ /\[XYZ\]/ ) a=1;  if ( $0 ~
/\[\/XYZ\]/ ) a=0; if ( a == 1) print $0}'

or something close to it


Simpler yet

cat asdf.txt | grep -v XYZ | grep -v bla

Patrick.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Randal L. Schwartz
 Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr writes:

Patrick cat asdf.txt | grep -v XYZ | grep -v bla

And yet, you still have the Useless Use of Cat.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Devin Teske

On Jan 4, 2011, at 9:33 AM, Randal L. Schwartz wrote:

 Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr writes:
 
 Patrick cat asdf.txt | grep -v XYZ | grep -v bla
 
 And yet, you still have the Useless Use of Cat.

I know I'm joining the party late, but... what about:

grep -Ev '(XYZ|bla)' asdf.txt

or

awk '!/XYZ/  !/bla/ {print}' asdf.txt

ok... end useless contribution.

 
 -- 
 Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
 Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
 See http://methodsandmessages.posterous.com/ for Smalltalk discussion
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

--
Cheers,
Devin Teske

- CONTACT INFORMATION -
Business Solutions Consultant II
FIS - fisglobal.com
510-735-5650 Mobile
510-621-2038 Office
510-621-2020 Office Fax
909-477-4578 Home/Fax
devin.te...@fisglobal.com

- LEGAL DISCLAIMER -
This message  contains confidential  and proprietary  information
of the sender,  and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person  is strictly prohibited.  If you have  received this
message in error,  please notify  the e-mail sender  immediately,
and delete the original message without making a copy.

- FUN STUFF -
-BEGIN GEEK CODE BLOCK-
Version 3.1
GAT/CS d(+) s: a- C++() UB$ P++() L++() !E--- W++ N? o? K- w O
M+ V- PS+ PE Y+ PGP- t(+) 5? X+(++) R++ tv(+) b+(++) DI+(++) D(+) G+++ e+ h
r++ y+ 
--END GEEK CODE BLOCK--
http://www.geekcode.com/

- END TRANSMISSION -

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread RW
On Tue, 4 Jan 2011 10:01:47 -0800
Devin Teske dte...@vicor.com wrote:

 
 On Jan 4, 2011, at 9:33 AM, Randal L. Schwartz wrote:
 
  Patrick == Patrick Bihan-Faou
  patrick.bihan-f...@teambox.fr writes:
  
  Patrick cat asdf.txt | grep -v XYZ | grep -v bla
  
  And yet, you still have the Useless Use of Cat.
 
 I know I'm joining the party late, but... what about:
 
 grep -Ev '(XYZ|bla)' asdf.txt
 
 or
 
 awk '!/XYZ/  !/bla/ {print}' asdf.txt
 
 ok... end useless contribution.

It's odd that people seem to be taking bla-bla so literally, when it's
clearly a place holder for arbitary text. 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Devin Teske
On Tue, 2011-01-04 at 22:12 +, RW wrote:
 On Tue, 4 Jan 2011 10:01:47 -0800
 Devin Teske dte...@vicor.com wrote:
 
  
  On Jan 4, 2011, at 9:33 AM, Randal L. Schwartz wrote:
  
   Patrick == Patrick Bihan-Faou
   patrick.bihan-f...@teambox.fr writes:
   
   Patrick cat asdf.txt | grep -v XYZ | grep -v bla
   
   And yet, you still have the Useless Use of Cat.
  
  I know I'm joining the party late, but... what about:
  
  grep -Ev '(XYZ|bla)' asdf.txt
  
  or
  
  awk '!/XYZ/  !/bla/ {print}' asdf.txt
  
  ok... end useless contribution.
 
 It's odd that people seem to be taking bla-bla so literally, when it's
 clearly a place holder for arbitary text. 

Maybe because the OP should have said:

How do I get the text between [XYZ] and [/XYZ]

A demarcing field-search is different than a pruning line-search.

This is what the OP was looking for:

awk -v tag=XYZ '
BEGIN { buf =  }
$0 ~ \\[tag\\], $0 ~ \\[/tag\\] \
{
if ( match($0, \\[/tag\\]) ) \
{
buf = buf substr($0, 0, RSTART - 1)
sub(.*\\[tag\\], , buf)
sub(/^\n*/, , buf)
sub(/\n*$/, , buf)
print buf
buf = 
next
} else
buf = buf $0\n
}
END { if ( length(buf) ) print buf }' asdf.txt

or, if you would prefer to have it all on one line:

awk -v tag=XYZ 'BEGIN { buf =  } $0 ~ \\[tag\\], $0 ~ \\[/tag\
\] { if ( match($0, \\[/tag\\]) ) { buf = buf substr($0, 0, RSTART
- 1); sub(.*\\[tag\\], , buf); sub(/^\n*/, , buf); sub(/\n*$/,
, buf); print buf; buf = ; next } else buf = buf $0\n } END { if
( length(buf) ) print buf }' asdf.txt

or, if you would like it as an alias:

for bash...

alias between_xyz='awk -v tag=XYZ '\''BEGIN { buf =  } $0 ~ \\[tag\
\], $0 ~ \\[/tag\\] { if ( match($0, \\[/tag\\]) ) { buf = buf
substr($0, 0, RSTART - 1); sub(.*\\[tag\\], , buf); sub(/^\n*/,
, buf); sub(/\n*$/, , buf); print buf; buf = ; next } else buf =
buf $0\n } END { if ( length(buf) ) print buf }'\'

for csh:

alias between_xyz 'awk -v tag=XYZ '\''BEGIN { buf =  } $0 ~ \\[tag\
\], $0 ~ \\[/tag\\] { if ( match($0, \\[/tag\\]) ) { buf = buf
substr($0, 0, RSTART - 1); sub(.*\\[tag\\], , buf); sub(/^\n*/,
, buf); sub(/\n*$/, , buf); print buf; buf = ; next } else buf =
buf $0\n } END { if ( length(buf) ) print buf }'\'

Usage:

between_xyz asdf.txt

Of course, this can even be improved upon further...

As a shell function:

# between $what $file [$file ...]
#
# Split out lines between [$what] and [/$what] using awk(1).
#
between()
{
awk -v tag=$1 '
BEGIN { buf =  }
$0 ~ \\[tag\\], $0 ~ \\[/tag\\] \
{
if ( match($0, \\[/tag\\]) ) \
{
buf = buf substr($0, 0, RSTART - 1)
sub(.*\\[tag\\], , buf)
sub(/^\n*/, , buf)
sub(/\n*$/, , buf)
print buf
buf = 
next
} else
buf = buf $0\n
}
END { if ( length(buf) ) print buf }
' $@
}

Or, for those csh users, how about a fancy alias?:

alias between 'awk -v tag=\!^ '\''BEGIN { buf =  } $0 ~ \\[tag\
\], $0 ~ \\[/tag\\] { if ( match($0, \\[/tag\\]) ) { buf = buf
substr($0, 0, RSTART - 1); sub(.*\\[tag\\], , buf); sub(/^\n*/,
, buf); sub(/\n*$/, , buf); print buf; buf = ; next } else buf =
buf $0\n } END { if ( length(buf) ) print buf }'\'' \!:2-$'

Usage:

between XYZ asdf.txt

AND... (lol)... last but not least...

If you want to have case-insensitivity, you'll have to change:

BEGIN { buf =  }

to:

BEGIN { IGNORECASE = 1; buf =  }


NOTE: FYI, when you need to grab text that spans multiple lines between
two field delimiters, C/C++ is superior to perl/awk which excel at line-
based I/O versus block I/O. However, I conclude that the OP wanted
something that was executable from the command-line (considering that
he/she actually gave a basic construct for a perl one-liner (which might
as well be an awk one-liner considering FreeBSD doesn't come with Perl
in the base anymore and thus not every machine is guaranteed to have
perl -- while every machine has awk).

ANOTHER NOTE: The above is not intended to start a language flame-war...
just an observation. If you have observed an easy _and_ convenient
method that _does_ use perl/awk (in a manner more efficient than the
above), I'm sure the OP/list would love it. Otherwise, I really do view
this operation as being easier in C using functions like strchr,
strrchr, etc.
-- 
Cheers,
Devin Teske

- CONTACT INFORMATION -
Business Solutions Consultant II
FIS - fisglobal.com
510-735-5650 Mobile
510-621-2038 Office
510-621-2020 Office Fax
909-477-4578 Home/Fax
devin.te...@fisglobal.com

- LEGAL DISCLAIMER -
This message  

Re: a perl question

2011-01-04 Thread Randal L. Schwartz
 RW == RW  rwmailli...@googlemail.com writes:

RW It's odd that people seem to be taking bla-bla so literally, when it's
RW clearly a place holder for arbitary text. 

That's the problem when you provide an example instead of a rule.  But
oddly enough, once you figure out the actual rule, translating that into
a program is generally rather mechanical.  Hence the irony of such
questions.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Chad Perrin
On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
  Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr writes:
 
 Patrick cat asdf.txt | grep -v XYZ | grep -v bla
 
 And yet, you still have the Useless Use of Cat.

The weirdest thing about most useless uses of cat is that not using cat
would actually be a little clearer and involve fewer keystrokes -- as in
this case.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


pgpaBZTKvL8ix.pgp
Description: PGP signature


Re: tricky perl question - ascending order

2010-05-23 Thread Randal L. Schwartz
 Jozsi == Jozsi Vadkan jozsi.avad...@gmail.com writes:

Jozsi So from the input, i want to make an ascendant order, how many things
Jozsi are under a SOMETHING-XX

So you just want paragraphs ordered by line count?

Something like this, untested:

perl -00 'print map $_-[0], sort { $a-[1] = $b-[1] } map [$_, tr/\n//], 
' input output

Keywords: Schwartzian Transform, paragraph mode.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: tricky perl question - ascending order

2010-05-23 Thread Jozsi Vadkan
The solution [i asked Randal L. Schwartz, because i didn't worked, and
he said he just forgot the -e, now it works!!]:

perl -00 -e 'print map $_-[0], sort { $a-[1] = $b-[1] } map [$_,
tr/\n//], '  before.txt  after.txt

Thank you!!


  Jozsi == Jozsi Vadkan jozsi.avad...@gmail.com writes:
 
 Jozsi So from the input, i want to make an ascendant order, how many things
 Jozsi are under a SOMETHING-XX
 
 So you just want paragraphs ordered by line count?
 
 Something like this, untested:
 
 perl -00 'print map $_-[0], sort { $a-[1] = $b-[1] } map [$_, tr/\n//], 
 ' input output
 
 Keywords: Schwartzian Transform, paragraph mode.
 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: OT - Perl Question

2003-11-11 Thread Fernando Gleiser
On Tue, 11 Nov 2003, Darryl Hoar wrote:


 if ( $nation eq British  or  $nation eq New Zealand )
 {
  print Hallo $name, pleased to meet you!\n;

 }

 when I try to run it, it generates a compile errors on the
 if line.

 I know its the conditional test, but don't know how to fix
 it to be syntactically correct in perl.

Precedence errors, change it to:

if ( ($nation eq British)  ||  ($nation eq New Zealand) )

When in doubt, parentesize defensivelly :)

Hope this helps.


Fer


 Any help?

 thanks,
 -D
 ___
 [EMAIL PROTECTED] mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: OT - Perl Question

2003-11-11 Thread Matthew Seaman
On Tue, Nov 11, 2003 at 02:57:04PM -0600, Darryl Hoar wrote:
 I am trying to learn perl.  I am going through a tutorial and have come
 across a syntax error I can't figure out.
 
 Here's the code:
 
 print Please tell me your name: ;
 chop ($name=STDIN);
 
 print Please tell me your nationality: ;
 chop ($nation=STDIN);
 
 if ( $nation eq British  or  $nation eq New Zealand )
 {
  print Hallo $name, pleased to meet you!\n;
 
 }
 
 when I try to run it, it generates a compile errors on the
 if line.
 
 I know its the conditional test, but don't know how to fix
 it to be syntactically correct in perl.
 
 Any help?

Works fine if you ask me:

happy-idiot-talk:/tmp:% cat  foo.pl
#!/usr/bin/perl -w

print Please tell me your name: ;
chop ($name=STDIN);

print Please tell me your nationality: ;
chop ($nation=STDIN);

if ( $nation eq British  or  $nation eq New Zealand )
{
 print Hallo $name, pleased to meet you!\n;

}

happy-idiot-talk:/tmp:% perl -cw foo.pl 
foo.pl syntax OK
happy-idiot-talk:/tmp:% chmod +x foo.pl 
happy-idiot-talk:/tmp:% ./foo.pl 
Please tell me your name: Matthew
Please tell me your nationality: British
Hallo Matthew, pleased to meet you!

There was probably a typo in your original script which you've managed
to inadvertently fix when you copied your code into the e-mail.

Cheers,

Matthew


-- 
Dr Matthew J Seaman MA, D.Phil.   26 The Paddocks
  Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614  Bucks., SL7 1TH UK


pgp0.pgp
Description: PGP signature