Help with a pagraph to be display as a one big line

F

felipe.garcia

Hi to all.
i am new and learning to do things with perl.
i need some help.
I have
59 0191 00010000 00000000 00000000 1 2 0 **/**/**** 01/25/2000
**/**/**** 40599.46 .00 .000 0 250000.00 .00 35000.00 .00
35000.00 .00 35000.00 .00 35000.00 .00 35000.00 .00

I need some type of fuction to get this code and put it in to an
arrary. i have this function

if (/ 59 0191 /) {
$seg59 = $_;

while (<DATA>) {
if (/^\s+/) {$seg59 = "$seg59$_"}
if (/^\d/) {last}

but if I display $seg59 only display the first line of the pagraph. I
need the whole pagraph to be input into $seg59. any suggestions?
thank you
 
P

Paul Lalli

Hi to all.
i am new and learning to do things with perl.
i need some help.
I have
59 0191 00010000 00000000 00000000 1 2 0 **/**/**** 01/25/2000
**/**/**** 40599.46 .00 .000 0 250000.00 .00 35000.00 .00
35000.00 .00 35000.00 .00 35000.00 .00 35000.00 .00

I need some type of fuction to get this code and put it in to an
arrary. i have this function

if (/ 59 0191 /) {
$seg59 = $_;

while (<DATA>) {
if (/^\s+/) {$seg59 = "$seg59$_"}
if (/^\d/) {last}

but if I display $seg59 only display the first line of the pagraph. I
need the whole pagraph to be input into $seg59. any suggestions?
thank you

You're contradicting yourself. You said you want the entire text in an
array, but your code is creating one large scalar variable. Which is
it?

You're also not showing enough of the script for us to know what it is
you're doing. How is $_ being assigned before the if() statement?

(This would be a good time for you to read the Posting Guidelines that
are posted to this group twice a week)

If you want the entirety of a file to be read into one scalar, modify
the $/ variable:

#!/usr/bin/perl
use strict;
use warnings;

my $contents;
{
local $/; #enable "slurp" mode
$contents = <DATA>;
}

print "Contents: \n$contents\n";

__DATA__
59 0191 00010000 00000000 00000000 1 2 0 **/**/**** 01/25/2000
**/**/**** 40599.46 .00 .000 0 250000.00 .00 35000.00 .00
35000.00 .00 35000.00 .00 35000.00 .00 35000.00 .00


=====Output=====
Contents:
59 0191 00010000 00000000 00000000 1 2 0 **/**/**** 01/25/2000
**/**/**** 40599.46 .00 .000 0 250000.00 .00 35000.00 .00
35000.00 .00 35000.00 .00 35000.00 .00 35000.00 .00


Read more about the $/ variable in:
perldoc perlvar
 
A

attn.steven.kuo

Hi to all.
i am new and learning to do things with perl.
i need some help.
I have
59 0191 00010000 00000000 00000000 1 2 0 **/**/**** 01/25/2000
**/**/**** 40599.46 .00 .000 0 250000.00 .00 35000.00 .00
35000.00 .00 35000.00 .00 35000.00 .00 35000.00 .00

I need some type of fuction to get this code and put it in to an
arrary. i have this function

if (/ 59 0191 /) {
$seg59 = $_;

while (<DATA>) {
if (/^\s+/) {$seg59 = "$seg59$_"}
if (/^\d/) {last}

but if I display $seg59 only display the first line of the pagraph. I
need the whole pagraph to be input into $seg59. any suggestions?
thank you



Your question isn't clear. Perhaps you want the multi-line range
operator (...) to excerpt a portion of a file? E.g.,

my $seg59;
while (<DATA>)
{
if (/^59 0191(?{1;})/ ... /^\d+(?{0;})/)
{
$seg59 .= $_ if $^R;
last unless $^R;
}
}

print $seg59;

__DATA__
Hello
World
59 0191
more stuff
here
99 86
Cone of Silence
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,946
Members
47,497
Latest member
PilarLumpk

Latest Threads

Top