Hi All,

I'm trying to parse long text strings to upload into various tables in a database, nd have managed to break down the strings into pieces such as FIL.date=2009-0707, SPE.reference_channel=4.097e+03, etc, whereby FIL, SPE, etc are the names of the tables in the database, date, reference_channel, etc are column headers in appropriate tables, and the values following "=" are meant for each column.

I thought it'd be easier to upload data to the database if entries to each table are organized into an hash while parsing the strings. To that end, I have the following, so far:

open (my $fd, '<','./dump2.txt') or die "Can't open dump2.txt"; while (<$fd>) { chomp; my @dump = split(/\t/); my $tbl_last = "FIL"; foreach my $it (@dump) { if ($it =~ m/([A-Z]{3})\.(.+)/) { my $tbl = $1; my ($col, $val) = split('=',$2); # print "$it\t$tbl\t$col\t$val\n"; my @tmp = (); if ($tbl eq $tbl_last) { push(@tmp,$col,$val); } else { my %$tbl = (@tmp); $tbl_last = $tbl; print Dumper \%$tbl; } } } }

It didn't like %$tbl. I tried %($tbl) and %"$tbl", all to noavail. Perhaps this is the wrong approach to the problem? Any suggestions/advice appreciated.

here's the first line of the dump2.txt file:

FIL.date=2009-07-07 FIL.file_name="/opt/uip/data/class/55019.cso" + INH.sca n_number=1 INH.obs_number=1 INH.scan_type=5 INH.u +t_date_tim e="2009-07-07 04:18:55" INH.azimuth=9.0150894e+01 INH.elevation +=5.9999599 e+01 INH.tau_225=5.5000000e-02 MAP.ra_offset=0.0000000e+00 + MAP.dec _offset=0.0000000e+00 MAP.az_offset=0.0000000e+00 MAP.el_offset +=-0.000000 0e+00 MAP.gl_offset=0.0000000e+00 MAP.gb_offset=0.0000000e+00 + SOU.sou rce_name="Freq Cal" SOU.ra_epoch=0.0000000000000000e+00 SOU.d +ec_epoch=0 .0000000000000000e+00 SOU.epoch=0.0000000e+00 SOU.velocity= +-5.7749530 e-13 SOU.velocity_type=0 SOU.off_mode=0 SOU.off_x=0 SOU.o +ff_y=0 SPE.spectrometer_number=5 SPE.receiver_number=0 SPE.line_name +="12co2-1" SPE.rest_frequency=2.3053797000000000e+02 SPE.lock_freq +uency=0.00 00000000000000e+00 SPE.if_frequency=0.0000000000000000e+00 + SPE.sid eband=0 SPE.harmonic=0 SPE.frequency_offset=0.0000000000000000e+00 + SPE.vel ocity_offset=0.0000000000000000e+00 SPE.if_offset=0.0000000000000 +000e+00 SPE.bandwidth=1.3311705e+03 SPE.number_channels=2048 SPE.r +eference_c hannel=9.2074707e+02 SPE.system_temperature=1.0000000e+00 SPE.o +n_time=1.0 156640e+00 SPE.off_time=0 TEL.fixed_az_offset=0.0000000e+00 + TEL.fix ed_el_offset=-0.0000000e+00 TEL.focus_offset=0 TEL.y_offset= +0 TEL.sec ondary_x=0 TEL.secondary_y=0 TEL.secondary_z=0 TEL.s +econdary_t heta=0 TEL.ut_date_time="2009-07-07 04:18:55"

In reply to how to initiate an array or an hash with name from captured string in pattern matching? by hihilo

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.