Hi Rob,

Once again your expertise and willingness to help is astounding.

I appreciate the idea that everyone else is trying to force me into learning
a new concept I have never
encountered before by giving me pointers in the direction such as telling me
to look at pack and unpack
or the CSV related modules, which are all good, but I found that often
learning through example and then
take what I've learned and expand on that going forth usually works for me.

The fact that you went the extra mile and actually gave me a real example
based on what I need, not
only do I learn from this, but I also grasp it much quicker than having to
first learn the entire new concept
such as pack, unpack or the CSV related modules, but I also now have a very
good understanding from
which I can build on and have a good base from where I can dig deeper from
here.

Thank you very much for your assistance and literally showing me the ropes
and even explaining it so
that Perl newbies such as myself can understand it.

Perl is a great language and a great tool that is very useful in a wide
range of things, but grasping it's
power is often not easy for newcomers who want to know it, but don't always
have the time to reinvent
the wheel, which is why standing on the shoulders of giants who does
understand these things and who
are willing to share their expertise and guide newcomers such as myself so
that many more in future can
eventually do what you do and so have a "return of investment" by helping
the Perl community grow even
faster as to keep it obscured and out of reach for the norm.

Personally, I am a Java developer and Linux Admin of profession and don't
always have the time as much
as I would love to have digging into the finer details and aspects of
things, and understand that I will not and
cannot possibly know everything there is to know about any particular
subject, but know there are people such
as yourself out there willing to lend a hand and point those such as myself
not only in the right direction, but also
providing the map to get there. All I need to do is follow the road, and
then build my own maps based on what
I have learned from people such as yourself.

Regards,
Wernher

On 25 June 2011 19:02, Rob Dixon <rob.di...@gmx.com> wrote:

> On 24/06/2011 08:45, Wernher Eksteen wrote:
> >
> > I've attached a text file containing the original and required
> > format and avoid the format being lost by just pasting it in the
> > email body.
> >
> > The original format is separated by a space, but need to replace the
> > space with a comma, so it will become a comma delimited csv file
> > which I will then import to MS Excel.
> >
> > I'm not sure how to parse the "Connection" and "Sync'ed-as-of-time"
> > columns since the dates there in is in this format "Fri Jun 24
> > 06:37" which also separated by space, but the spaces in those
> > columns shouldn't be replaced by a comma. The date format in those
> > columns should remain the same.
> >
> > Also, is it possible to convert this directly into a MS Excel
> > document using Perl?
>
> Hello again Wernher.
>
> My first guess for this problem was to build an 'unpack' format based on
> the row of hyphens beneath the header captions. As it may still be
> useful, and well worth studying for similar applications, here is my
> alternative solution doing just that.
>
> The program grabs everything in the file that is aligned with the row
> of hyphens beneath the captions. It works by finding the first line in
> the file that contains only hyphens or spaces, and scanning that to
> build an unpack string using the @- and @+ arrays that hold the offsets
> of the start and end of the previous successful regex match.
>
> Unlike my previous solution, empty (all-space) fields are handled
> correctly: the 'A' unpack format discards trailing spaces, and my only
> proviso is that if you ever expect leading spaces in fields they must be
> trimmed explicitly.
>
> HTH,
>
> Rob
>
>
> use strict;
> use warnings;
>
> use Fcntl 'SEEK_SET';
>
> my $format;
>
> my $fh = *DATA;  # Replace with the appropriate 'open my $fh, '<', ... or
> die $!;
>
> # Remember the where the file begins, and then build the unpack pattern
> from
> # the first line continaining only hyphens and underscores
> #
> my $bof = tell $fh;
> while (<DATA>) {
>  chomp;
>  if (tr/- //c == 0 and tr/-// > 0) {
>    while (/-+/g) {
>      my ($beg, $len) = ($-[0], $+[0] - $-[0]);
>      $format .= "\@$beg A$len ";
>    }
>    last;
>  }
> }
>
> warn qq(Data will be upacked with a format of "$format"\n\n);
>
> # Now rewind to the beginning of the file, ignore anything that contains
> only
> # whitespace, and unpack every record according to the pattern that we just
> built
> #
> seek $fh, $bof, SEEK_SET;
> while (<$fh>) {
>  next unless /\S/;
>  my @data = unpack $format;
>  print join ',', @data;
>   print "\n";
> }
>
>
> __DATA__
>
>
> CTX   Destination
>   Enabled   Connection         Sync'ed-as-of-time
> ---   ---------------------------------------------------------------------
>   -------   ----------------   ------------------
> 1     pool://ZABRYDD01.localdomain/RDP_NEW_REP
>    yes       Sat Jun 18 08:56   Fri Jun 24 06:37
> 2     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101
>    yes       Sat Jun 18 08:57   Fri Jun 24 08:01
> 4     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22
>   yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 5     pool://ZARDPDD01.localdomain/BRYREP
>   yes       Sat Jun 18 08:57   Fri Jun 24 07:01
> 8     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31
>   yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 10    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421
>    yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 12    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5
>    yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 13    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60
>   yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> ---   ---------------------------------------------------------------------
>   -------   ----------------   ------------------
>
> **OUTPUT**
>
> Data will be upacked with a format of "@0 A3 @6 A69 @78 A7 @88 A16 @107 A18
> "
>
> "CTX","Destination","Enabled","Connection","Sync'ed-as-of-time"
>
> "---","---------------------------------------------------------------------","-------","----------------","------------------"
> "1","pool://ZABRYDD01.localdomain/RDP_NEW_REP","","Sat Jun 18 08:56","Fri
> Jun 24 06:37"
> "2","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101","yes","Sat
> Jun 18 08:57","Fri Jun 24 08:01"
> "4","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22","yes","Sat
> Jun 18 08:57","Fri Jun 24 09:00"
> "5","pool://ZARDPDD01.localdomain/BRYREP","yes","Sat Jun 18 08:57","Fri Jun
> 24 07:01"
> "8","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31","yes","Sat
> Jun 18 08:57","Fri Jun 24 09:00"
> "10","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421","yes","Sat
> Jun 18 08:57","Fri Jun 24 09:00"
> "12","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5","yes","Sat
> Jun 18 08:57","Fri Jun 24 09:00"
> "13","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60","yes","Sat
> Jun 18 08:57","Fri Jun 24 09:00"
>
> "---","---------------------------------------------------------------------","-------","----------------","------------------"
>

Reply via email to