Hi starface245,
from your code:
.....
if ($line =~ /(address............)/) #13 dots for 13characters
{
my @values = split(' ', $line);
foreach my $val (@values) {
print "$val\n";
}
......
your
foreach loop will only print out the following:
address
6433
main
st
address
6434
main
st
address
6435
main
st
Thanks to the
split function used to create array @values
Atleast, this is one of the many reasons, why you can't insist on your "ways" when asking for help.
However, If you must but have the same code structure, then I believe the script below could help:
#!/usr/bin/perl
use warnings;
use strict;
my @values;
while (<DATA>) {
my ($line) = $_;
chomp($line);
if ( $line =~ m/^address/ ) {
push @values, split( ' st ', $line );
}
else {
print $line, $/;
}
}
print $_, ' st', $/ foreach @values;
__DATA__
This is the list of address
here are the addreses
address 6433 main st address 6434 main st address 6435 main st
OUTPUT:
This is the list of address
here are the addreses
address 6433 main st
address 6434 main st
address 6435 main st
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.