in reply to Question on anon hashes

In your closing request:

Without concatenating the data lines, or using a subhash on the hash, is there a way I can keep all that data keyed together?

Is there some reason why you need to avoid concatenating the data lines, or using a multi-level hash? Because I think either of those (actually both) would suit what I think you want... fever's point about joining the regexes seems like a very plausible place to start:

foreach $line(@urllist){ $data = get($line); if ( $data =~ m!$regex1\r?\n$regex2!io ) { $school->{school} = $1; ($school->{school}{addr}, $school->{school}{city}, $school->{school}{zip}, $school->{school}{phone}, $school->{school}{level}) = ($2,$3,$4,$5,$6); } # might the two lines show up in reverse order? then elsif ( $data =~ m!$regex2\r?\n$regex1!io ) { $school->{school} = $3; ($school->{school}{addr}, $school->{school}{city}, $school->{school}{zip}, $school->{school}{phone}, $school->{school}{level}) = ($4,$5,$6,$1,$2); } else { next } print join $/, $school->{school}, map{$school->{school}{$_}} qw/addr city zip phone level/; print $/; };
Did I draw the right conclusions about your data? Does this break some condition that you left out of your post? (update: fixed indentation)

Replies are listed 'Best First'.
Re: Re: Question on anon hashes
by Popcorn Dave (Abbot) on Aug 21, 2002 at 04:17 UTC
    Thanks for that!

    The multi-level hash idea just came to me before I read your post. I don't know why I didn't think of it this afternoon while I was coding this.

    As far as the regex goes, the data is on 2 seperate lines, so I don't think that combining the regex is necessarily the way to go. The multi-level hash idea seems the easiest for this program, keying on the school like you did.

    Thanks again!

    Some people fall from grace. I prefer a running start...

      As far as the regex goes, the data is on 2 seperate lines, so I don't think that combining the regex is necessarily the way to go

      Hmmm. Well, your original code seemed to assume that those two separate lines were somehow stored in a single scalar sting, as in: "$data = get($line)" -- because after $data gets its value from this sub call, you split it with /\r?\n/. (you originally used /\r\n|\n/, which does the same thing.)

      So that's why I suggested ditching the split, and just looking for the combination of your two regexes separated by the line separator that was apparently embedded in $data.