Ok, my code WAS really really long...  shoot me for being a newbie :c)

Thanks a lot Ron!

G


At 20:08 03/02/2001, you wrote:
> > This is contained on one field returned by DBI. What I'd like to do is
> > take a hacket to it and just be left with:
> >
> > "GONZALO" and "Welcome to the customer service area of our web site."
>
># your $data
>
>my($bUid,$fAct) = $data =~ m|.*S{(.+?)}bUid .* S{(.+?)}fAct |;
>
>print "buid: $bUid\nfact: $fAct";
>
> > I have written code that will do that (included below) but it is not
> > very portable and it's kinda lengthy for being perl..
>
>I thought my code was lengthy...
>
> > What would be a heaven sent is if I could use variables in a regular
> > expression, something like $szVal =~ /$szPattern1(.*)$szPattern2/ but
> > I don't see anywhere I can do that..  I have read the O'Reilly
> > Mastering Regexes book cover to cover, no hints..
>
>Its possible. What you have should work. When in doubt try:
>
>  $szPattern1 = qr|foo|; # quote regexp
>
> > Does anyone know a better way to extract what I need?
> >
> > Here is the code that I have...  It's working...  but I'm only looking
> > for the specified values, if I have to look for something else within
> > the string, this will not cut it...
>
>This a quick hack that lets you extract certain fields by name from the
>string. Passed the data string, and the fields 'bUid' and 'bUsr' it
>returns this data structure:
>
>$VAR1 = {
>           'bUid' => 'GONZALO',
>           'bUsr' => 'WCS-STD'
>         };
>
>I suppose you could make it faster by not iterating through the string
>per each item you want to find.
>
>use strict;
>use Data::Dumper;
>
>my $data = 'O{bTyp | S{WCS-STD}bUsr | S{GONZALO}bUid | S{REP.352637}sId
>| A{}sNme | S{}sUrl | S{}sLbl | S{}sCok | S{}mMsg | S{Welcome to the
>customer service area of our web site.}fAct |S{}fTyp | S{}fKey | S{}fVal
>| S{}}';
>
>my $hash_ref = extract($data,qw|bUsr bUid|);
>
>print Dumper $hash_ref;
>
>#============
>sub extract {
>#============
>
>my $data = shift;
>my %hash;
>
>foreach my $item ( @_ ) {
>
>  if ( $data =~ m#.*(?:S|A){(.+?)}$item # ) {
>   $hash{$item} = $1
>  }
>
>}
>
>  return \%hash;
>
>} # end sub

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to