Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Re: Re: Re: Re: Re: Non-fixed data in record

by brassmon_k (Sexton)
on Aug 31, 2001 at 22:42 UTC ( #109486=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Re: Re: Non-fixed data in record
in thread Non-fixed data in record

Yes, that is it but I want to have only the "radioChannelProperty" line print. That will print what you showed above. It matches and prints the whole block. Now I can't tell it to print off $line2 if it's "radioChannelProperty" even though that's what I want because in the next record block "radioChannelProperty" could be on line3 so I have to devise a way of telling it to print the "radioChannelProperty" line when it isn't always on the same line for every record block. So in the best way I can explain it, and this isn't proper syntax.

while block subheading equals "msterminating"
if match "radioChannelProperty" on line5 print line5 or if
match "radioChannelProperty" on line10 print line10

elsif subheading equals "msoriginating"
if match "radioChannelProperty" on line2 print line2 or if
match "radioChannelProperty" on line8 print line8

The Brassmonk


Comment on Re: Re: Re: Re: Re: Re: Re: Non-fixed data in record
Keep It Simple, S*****
by dragonchild (Archbishop) on Aug 31, 2001 at 22:47 UTC
    Don't change $/. Don't do anything of the sort. You have a textfile containing a piece of information per line. Use \n the way it was supposed to be used!
    open IN_FILE, "<my_in_file" or die "Cannot open my_in_file\n"; LINE: whle (<IN_FILE) { # This is a big block if (/^\S/) { } elsif (/^\s{2}\S/) { # Do what you want to do for middle hash } elsif (/^\s{4}\S/) { # Do what you want to do for inner hash } else { die "Bad line in datafile\n"; } } close IN_FILE;
    You are reading the file in one line at a time, not one block at a time. Don't make things complicated.

    K-I-S-S

    ------
    We are the carpenters and bricklayers of the Information Age.

    Vote paco for President!

      I believe this is more simple than all of your examples but everybody has their idea of simple.
      #!/usr/bin/perl -w chomp($msisdn = <STDIN>); $/ = ""; # read paragraphs @lines = split(/\n/, $_); if (@lines == 1) # A Heading { $lastHeading = $lines[0] next; } if ($lines[1] =~ "mSTerminating") { print("$lines[4]\n") if($lines[4] =~ "recordSequenceNumber"); } }
      I know "lastHeading" isn't defined yet along with "msisdn" but this worked! It delimits what is printed by the subheading. I can also add in more delmiters because for the phone number line even though that one moves around I'll just tell it to match the phone number delimited by the subheading off of $_ so I don't have to worry.

      So if the script finds subheading "mSTerminating" and if it finds a match for "recordSequenceNumber" then it prints line 4. See I found out in my datablocks that "recordSequenceNumber" is in lines4, 5, or 8 so I just say
      print line4 if "recordSequenceNumber" is matched on line4
      print line8 if "recordSequenceNumber" is matched on line8

      Of course this is in it's very prelim form I just wanted to show ya that I found an easy way.

      The Brassmon_k

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://109486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2014-09-20 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls