Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Positional Pattern-Matching

by PodMaster (Abbot)
on Sep 24, 2002 at 02:02 UTC ( [id://200275]=note: print w/replies, xml ) Need Help??


in reply to Positional Pattern-Matching

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-03-28 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found