[Chicago-talk] messy scalar into an array.
Richard Reina
richard at rushlogistics.com
Tue Mar 2 14:14:09 PST 2010
Hi Brian,
I really appreciate the reply. It looks promising, but it does not seem to trap any data. If I put a print $mode . " " . $ident . " " . $file . "\n";
after the matching statement nothing matches.
---- Chicago.pm chatter <chicago-talk at pm.org> wrote:
>
> As an alternative to fixed fields, how about:
>
> use strict;
> my @received = `faxstat -r`;
> my $line;
> my ($mode, $ident, $time, $file);
>
> foreach $line (@received) {
> if (($mode, undef, undef, $ident, $time, $file) =
> ($line =~
> /^(\S+)\s+(\d+)\s+(\d+)\s+(\S.*\S)?\s+(..:..)\s+(.*\.tif)$/) {
> # do whatever
> }
> }
>
> This should also deal with skipping irrelevant (fax title?) lines.
>
> - Brian
>
> Richard Reina wrote:
> > Actually, I believe all the suggestion would work until I realized
> > that every now in then there is a column that is completely blank and
> > then it throw everything off. Here is an example of the output:
> >
> > -rw---- 2 14 <UNSPECIFIED> 14:53 fax00003459.tif
> > -rw---- 1 14 501 443 9393 14:58 fax00003460.tif
> > -rw---- 1 14 15:01 fax00002470.tif
> >
> > That occasional empty column messes it up. Is there a way to
> > accommodate for that?
> >
> > Sorry, for the added wrinkle. I had not noticed that before.
> >
> > Richard
> > *
> > *
> >
> >
> > On Tue, Mar 2, 2010 at 8:46 AM, Richard Reina
> > <richard at rushlogistics.com <mailto:richard at rushlogistics.com>> wrote:
> >
> > I'm sorry for asking what likely should be a simple question
> > but after spending a fair amount of time playing with qw(),
> > split(), join(), etc. I still have not figured it out.
> >
> > I have some fairly messy system output which I have managed to
> > isolate into a scalar with
> >
> > use strict;
> > my @received = `faxstat -r`;
> >
> > I can't figure out how to neatly get this into an array so I
> > can get the output into a database table;
> >
> > I've gotten this far;
> >
> > my $line;
> > my @fax;
> >
> > foreach $line (@received) {
> >
> > if (substr($line,0,5) eq "-rw---") { # make sure it's an
> > actual fax
> > # and not the title of
> > the output
> > chomp($line);
> > }
> > }
> >
> > $line is exactly what I want but it's in the form of a scalar;
> > When I try to split it up into elements of an array with
> > @fax=split("", $line); it does not work due to all the back to
> > back white spaces. If anyone can help me out with a better
> > way to do this I would really appreciate it.
> >
> > Thanks,
> >
> > Richard
> > _______________________________________________
> > Chicago-talk mailing list
> > Chicago-talk at pm.org <mailto:Chicago-talk at pm.org>
> > http://mail.pm.org/mailman/listinfo/chicago-talk
> >
> >
>
> --
> Brian Katzung, Kappa Computer Solutions, LLC
> Leveraging UNIX, GNU/Linux, open source, and custom
> software solutions for business and beyond
> Phone: 877.367.8837 x1 http://www.kappacs.com
>
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
More information about the Chicago-talk
mailing list