Re: A question on output of flip flop operator (part 2)

From: phaylon (phaylon_at_dunkelheit.at)
Date: 02/08/05


Date: Tue, 08 Feb 2005 16:48:59 +0100

justme wrote:

> i have a text file with some info like this:

Why are you opening another thread? I've got your last one facing this
topic right on second line.
 
> Am i going the correct way by doing the incomplete code below ? If not
> any better way to do that...thanks

It is *a* way to do that[1]. But you have to keep it exactly in this
order. Another approach may be to use the range operator (C<..>) to find
out if you are in the local/end section and then process each line.
Below's a quick example which also builds a little data structure you may
find useful.

hth,
phay

( [1] I haven't read your code complete, so I'm just talking about the
      *way of doing it.* )

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
 
my(@data, $section);
my $count = 0;
 
line: while( <DATA> ) {
    if( /^\[local\]$/i .. /^\[end\]$/i ) {
        chomp;
 
        #-- skip empty lines
        next line if /^\s*$/;
 
        #-- find current section
        $section = $1 and next line
          if /^\[(files|dest|server|local|end)\]$/i;
 
        #-- end means, we're out of any section, next line
        next line if $section eq lc 'end';
 
        #-- everything but files seems to be one-value
        $data[ $count ]{ $section } .= $_
          and next line
          unless $section eq lc 'files';
 
        #-- push files entry
        push @{$data[ $count ]{ $section }}, $_;
    }
    else {
        $count++;
    }
}
print Dumper \@data;
 
__DATA__
[local]
/home/user
[files]
test1.txt
test1.htm
[dest]
/home/dest
[server]
127.0.0.1
[end]
 
[local]
/home/user1
[files]
test1.dat
test2.txt
[dest]
/home/dest1
[server]
127.0.0.1
[end]
__END__

-- 
http://www.dunkelheit.at/
bellum omnium pater.


Relevant Pages

  • A question on output of flip flop operator (part 2)
    ... and then using Net::FTP module to transfer files from local directory ... Am i going the correct way by doing the incomplete code below? ...
    (comp.lang.perl.misc)
  • Re: Best way to read from directory with many files
    ... These files are ETL files which contain trace information. ... The database is on a different server. ... If you're CPU bound, then you can either partition the work ahead of time, ... Or you can have a central data structure that each thread consumes ...
    (microsoft.public.dotnet.framework)
  • Re: SQL Server Database Synchronization
    ... The dest db is an exact copy/replica of the source, no updates will be done on the dest db, the dest db should be updated on a daily basis. ... Server A in a Hospital with ISDN connection, server B at ISP, server A is updated on a daily basis by users, server B is readonly for external users, server B needs all data from Server A. ... > Wayne Snyder, MCDBA, SQL Server MVP ...
    (microsoft.public.sqlserver.programming)
  • Re: Live Patching (Re: More static type fun.)
    ... > Marc Battyani wrote: ... The object writes to the SQL database are stopped ... Generally you don't have a complete change of the data structure. ... important changes like this done without stopping the server. ...
    (comp.lang.lisp)
  • Re: Missing Rows in Destination Table
    ... Query on the server and it returns the number of row's DTS transfers run it ... else where the missing rows are there, I've check via the GUI and these row's ... "andrewharris" wrote: ... > which aren't in the dest table. ...
    (microsoft.public.sqlserver.dts)