Hue-Bond has asked for the wisdom of the Perl Monks concerning the following question:
I'm about to parse the output of xlsclients -la. It's like this:
Window 0x800022: Machine: genus Name: xterm Icon Name: xterm Command: xterm -u8 -geometry 156x62+190+-2 Instance/Class: xterm/XTerm Window 0xc00022: Machine: genus Name: ~ Icon Name: psh Command: xterm -e /usr/bin/psh Instance/Class: xterm/XTerm Window 0xe00001: Machine: genus Name: Gecko Icon Name: mozilla-bin Command: mozilla-bin Instance/Class: mozilla-bin/Mozilla-bin
There's no blank link between "paragraphs" so I can't use $/ = "\n\n". I want to do something simple that gives me whole paragraphs without eating anything (so $/ = "\nWindow" wouldn't fit). I'm thinking about reading six lines at a time but I find it ugly:
open my $fd, 'xlsclients -la|' or die "open: $!"; WHILE: while (1) { my @para; foreach (1..6) { my $line = <$fd>; defined $line or last WHILE; push @para, $line; } print "@para\n"; ## quotes intended in this small example } close $fd;
Is there anything more I can do?
--
David Serrano
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading chunks of text
by holli (Abbot) on Aug 21, 2006 at 08:06 UTC | |
|
Re: Reading chunks of text
by cog (Parson) on Aug 21, 2006 at 08:06 UTC | |
|
Re: Reading chunks of text
by shmem (Chancellor) on Aug 21, 2006 at 08:12 UTC | |
|
Re: Reading chunks of text
by Fletch (Bishop) on Aug 21, 2006 at 12:58 UTC | |
|
Re: Reading chunks of text
by GrandFather (Saint) on Aug 21, 2006 at 11:23 UTC |