Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Bug in script when users use long names

by Sparky (Initiate)
on Sep 25, 2013 at 00:14 UTC ( #1055571=perlquestion: print w/ replies, xml ) Need Help??
Sparky has asked for the wisdom of the Perl Monks concerning the following question:

Iím trying to work out a bug in my script. I need to accommodate for longer Snapshot names but longer names cause the date:time to wrap to a new line. My script is only properly grepping off the date and and smaller snapshot name. I need to accommodate longer snapshot names. In the first example output, the snapshot names are 1, 2, 3... In the second sample, the names begin with Snapxxxx.

#Source array @sourceResult = $sourceTelnet->cmd("$sourceGetsnapshots"); print @sourceResult; @sourceGrepsnaps = grep(/20(13|14)/, @sourceResult); print "This is sourceGrepsnaps\n"; print @sourceGrepsnaps; print "\n";

This is the output from @sourceResult, sample 1

Vdisk Serial Number Name Creation Date/Time + Status Status-Reason Source Volume Snap-pool Name Snap Data Uniq +ue Data Shared Data Priority User Priority Type ---------------------------------------------------------------------- +--------- vd02 00c0ff10f4370000be62415201000000 1 2013-09-24 10:00:30 + Available N/A rep_pri_vol sprep_pri_vol 0B 0B + 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd02 00c0ff10f4370000bf63415201000000 2 2013-09-24 10:04:47 + Available N/A rep_pri_vol sprep_pri_vol 0B 0B + 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd02 00c0ff10f4370000c76e415201000000 3 2013-09-24 10:51:51 + Available N/A rep_pri_vol sprep_pri_vol 0B 0B + 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd02 00c0ff10f4370000d87c415201000000 4 2013-09-24 11:51:52 + Available N/A rep_pri_vol sprep_pri_vol 0B 0B + 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd02 00c0ff10f4370000e68a415201000000 5 2013-09-24 12:51:50 + Available N/A rep_pri_vol sprep_pri_vol 0B 0B + 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd02 00c0ff10f4370000f698415201000000 6 2013-09-24 13:51:50 + Available N/A rep_pri_vol sprep_pri_vol 0B 0B + 0B 0x8000 0x0000 Replication snapshot(Current sync point)(Common sync point) ---------------------------------------------------------------------- +--------- Success: Command completed successfully. (2013-09-24 14:04:47)

This is the output from @sourceResult, sample 2

Vdisk Serial Number Name Creation Date/Time Status Status-Reason Source Volume Snap-pool Name Snap Data Unique Data Shared Data Priority User Priority Type + ---------------------------------------------------------------------- +-------- vd01 00c0ff10e1e50000eac6415201000000 Snap13800424740 2013-09-24 17:07:54 Available N/A rrep_pri_vol sprrep_pri_vol 0B 0B 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd01 00c0ff10e1e50000efc6415201000000 Snap13800424790 2013-09-24 17:07:59 Available N/A rrep_pri_vol sprrep_pri_vol 0B 0B 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd01 00c0ff10e1e50000f4c6415201000000 Snap13800424840 2013-09-24 17:08:04 Available N/A rrep_pri_vol sprrep_pri_vol 0B 0B 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd01 00c0ff10e1e50000f8c6415201000000 Snap13800424880 2013-09-24 17:08:08 Available N/A rrep_pri_vol sprrep_pri_vol 0B 0B 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd01 00c0ff10e1e50000ead1415201000000 Snap13800452900 2013-09-24 17:54:50 Available N/A rrep_pri_vol sprrep_pri_vol 0B 0B 0B 0x4000 0x0000 Replication snapshot(Old Common sync point) vd01 00c0ff10e1e50000fbdf415201000000 Snap13800488910 2013-09-24 18:54:51 Available N/A rrep_pri_vol sprrep_pri_vol 0B 0B 0B 0x8000 0x0000 Replication snapshot(Current sync point)(Common sync + point)
The output can be below or vice versa. Date:Time Snapshotname Date:Time Snapshotname Date:Time Snapshotname Date:Time Snapshotname

How would you go about exacting that information? Thanks

Comment on Bug in script when users use long names
Select or Download Code
Re: Bug in script when users use long names
by boftx (Chaplain) on Sep 25, 2013 at 00:28 UTC

    I will offer a (very) general approach, or hint rather.

    It appears that your data samples, especially sample 2, represents a form of fixed length records that consist of a header record that can be identified by have a non-space character in col 1 (assume 1-based col numbering) and continuation records identified by space characters in cols 1 and 2.

    Given that you can easily find the start of a master record, and that there appears to be a standard structure to the continuation records, then unpack becomes your best friend and makes the actual extraction trivial.

    The presence of the header title records is what reduces this to a simple problem that unpack is uniquely intended to handle. All that you really need to do is keep track of what record/sub-record row number you are on so you apply the correct unpack pattern to it and extract the data to normal variables.

    On time, cheap, compliant with final specs. Pick two.

      Thanks Boftx, I'll check it out. Strange,pack/unpack never came up while I was figuring this out in all my perl books.

        Looking at this further I notice that there doesn't appear to be any kind of format version number in the header info. Shame on your source for that. But even so, it appears to a simple matter to just check to see if the Date/Time header is present in the first header line and if not you know you are dealing with (what I presume is) the newer data format.

        On a side note, this kind of data format has been largely replaced by XML for B2B data exchange. Some vendors have opted for a CSV format, but it is just simply amazing to see how many programmers can not generate a proper CSV file, or an XML file for that matter. There is still something to be said for a fixed length record after all. :)

        On time, cheap, compliant with final specs. Pick two.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-08-01 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls