Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You might wanna look into Parse::RecDescent. Anyway, something like this you ought to be able to do
#!/usr/bin/perl use strict; use Data::Dumper; eval q{use warnings;} or local $^W=1; my @SSS = (); OUTER: while (my $line = <DATA>) { chomp $line; if( @SSS ){ if( $line =~ /Daily Windows:/i ) { while($line = <DATA>) { if ($line =~ /schedule:\s+(\S+)/i){ push @SSS, { 'Schedule' => $1 }; next OUTER; }elsif($line =~/\w+\s+\d\d\:\d\d\:/){ my( $fDay, $fTime, $tDay, $tTime ) = grep/$_/,spli +t /\s+|-->/,$line; push @{$SSS[-1]->{ 'Windows' }}, [ $fDay, $fTime, $tDay, $tTime ]; } } }else{ my($a,$b) = split /\:/, $line, 2; $SSS[-1]->{ $a } = $b; } }elsif($line =~ /schedule:\s+(\S+)/i) { push @SSS, { 'Schedule' => $1 }; } } print Dumper \@SSS; __DATA__ Schedule: Full Type: Full Backup Frequency: every 1 day Retention Level: 2 (5 weeks) Maximum MPX: 1 Residence: (specific storage unit not required) Volume Pool: (same as class volume pool) Daily Windows: Saturday 02:00:00 --> Saturday 12:00:00 Schedule: CINC Type: Cumulative Incremental Backup Frequency: every 1 day Retention Level: 2 (5 weeks) Maximum MPX: 1 Residence: (specific storage unit not required) Volume Pool: (same as class volume pool) Daily Windows: Sunday 02:00:00 --> Sunday 12:00:00 Monday 02:00:00 --> Monday 12:00:00 Tuesday 02:00:00 --> Tuesday 12:00:00 Wednesday 02:00:00 --> Wednesday 12:00:00 Thursday 02:00:00 --> Thursday 12:00:00 Friday 02:00:00 --> Friday 12:00:00

$VAR1 = [
          {
            '   Volume Pool' => '     (same as class volume pool)',
            '   Type' => '            Full Backup',
            '   Residence' => '       (specific storage unit not required)',
            'Windows' => [
                           [
                             'Saturday',
                             '02:00:00',
                             'Saturday',
                             '12:00:00'
                           ]
                         ],
            '   Retention Level' => ' 2 (5 weeks)',
            'Schedule' => 'Full',
            '   Maximum MPX' => '     1',
            '   Frequency' => '       every 1 day'
          },
          {
            '   Volume Pool' => '     (same as class volume pool)',
            '   Type' => '            Cumulative Incremental Backup',
            '   Residence' => '       (specific storage unit not required)',
            'Windows' => [
                           [
                             'Sunday',
                             '02:00:00',
                             'Sunday',
                             '12:00:00'
                           ],
                           [
                             'Monday',
                             '02:00:00',
                             'Monday',
                             '12:00:00'
                           ],
                           [
                             'Tuesday',
                             '02:00:00',
                             'Tuesday',
                             '12:00:00'
                           ],
                           [
                             'Wednesday',
                             '02:00:00',
                             'Wednesday',
                             '12:00:00'
                           ],
                           [
                             'Thursday',
                             '02:00:00',
                             'Thursday',
                             '12:00:00'
                           ],
                           [
                             'Friday',
                             '02:00:00',
                             'Friday',
                             '12:00:00'
                           ]
                         ],
            '   Retention Level' => ' 2 (5 weeks)',
            'Schedule' => 'CINC',
            '   Maximum MPX' => '     1',
            '   Frequency' => '       every 1 day'
          }
        ];
I would guess "positional pattern matching" would somehow involve \G and pos, but that's just me (i'd call this simply parsing).

____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.


In reply to Re: Positional Pattern-Matching by PodMaster
in thread Positional Pattern-Matching by blink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-25 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found