[Chicago-talk] messy scalar into an array.

Richard Reina richard at rushlogistics.com
Wed Mar 3 07:37:40 PST 2010


I really appreciate everyone's response.  One of the beauties of perl -- aside from the outstanding user community -- is that there's more than one way to do things.  For now I'm going with substring, but I will keep an eye on how it's working and likely refer back to some of the other suggestions to make changes.

Thanks again, for all the ideas.

Richard
---- Alexander Danel <danel at speakeasy.net> wrote:
>
> It looks to me like "unpack" is the correct solution.  
> 
> Are there <tab> characters in this output?  That would change things.
> 
> -----Original Message-----
> From: chicago-talk-bounces+danel=speakeasy.net at pm.org
> [mailto:chicago-talk-bounces+danel=speakeasy.net at pm.org] On Behalf Of Shawn
> Carroll
> Sent: Tuesday, March 02, 2010 12:50 PM
> To: Chicago.pm chatter
> Subject: Re: [Chicago-talk] messy scalar into an array.
> 
> The output appears to be formated.  you may want to look at unpack.
> 
> my @this = unpack ('a7a1a3......', $string);
> 
> 
> shawn.c.carroll at gmail.com
> Perl Programmer
> Soccer Referee
> 
> 
> 
> On Tue, Mar 2, 2010 at 12:42, Richard Reina <richard at rushlogistics.com>
> 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
> >
> > Chicago.pm chatter <chicago-talk at pm.org> wrote:
> >
> > I have no idea what your faxstat -r output looks like, but why no collapse
> > all of the white space down to single spaces, then you can split on the
> > singles space:
> >
> > $line =~ s/\s+/ /g;
> >
> > then you can split on the single space.
> >
> >   DB<3> $line = 'a b  c   d     e       f';
> >   DB<4> $a=$line
> >   DB<5> $a =~ s/\s+/ /g;
> >   DB<6> p $a
> >  a  b  c  d  e  f
> >   DB<7> @a=split(" ", $a);
> >   DB<8> x @a
> > 0  'a'
> > 1  'b'
> > 2  'c'
> > 3  'd'
> > 4  'e'
> > 5  'f'
> >
> >
> > ydy
> >
> > On Tue, Mar 2, 2010 at 8:46 AM, Richard Reina <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
> >> http://mail.pm.org/mailman/listinfo/chicago-talk
> >
> >
> >
> > --
> > I take the "Shhhh" out of IT - ydy
> >
> > _______________________________________________
> > Chicago-talk mailing list
> > Chicago-talk at pm.org
> > http://mail.pm.org/mailman/listinfo/chicago-talk
> >
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
> 
> _______________________________________________
> 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