in reply to Re: getting the right stuff
in thread getting the right stuff

i tried the Text::ParseWords, and it gave me back something like:
: : : : : : : :
i probably didn't do it right. but, going back to what i was doing before, once i have the data i need in @records, isn't there a way to get the " out with s///? or something simple?

with the printing, what i want to do is lose the labels of ID, Dept, etc.

i've been going over this - over and over - and i think i understand what i have right up to @records. i can draw a picture of where the data is going right up till then. but i'm not sure what the data looks like by the time it's in @records.

i think what would probably solve all of my problems (because I would be able to call each item) is if i could assign a scalar variable to each item. so that i could say something like:
print $ID, $firstname $middlename $lastname\n; print $dept, $address, $phone\n;
does this make any sense?

Replies are listed 'Best First'.
Re: Re: Re: getting the right stuff
by arturo (Vicar) on Feb 06, 2001 at 19:20 UTC

    To get rid of a character from a string, use tr/"//d (you need to add the d on the end for tr to delete)... this is also really handy for a range of characters, e.g. tr/"'//d;. Of course you have to bind the tr operator to the string you want stripped as in $string =~ tr/A-Z/a-z/;

    HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      i don't know where to do the replacement. do i need to change @records into a scalar to do it?
Re: Re: Re: getting the right stuff
by chromatic (Archbishop) on Feb 06, 2001 at 21:24 UTC
    @records is just an ordered list. If you assigned to it directly, it would look something like:
    my @records; @records = qw( name ID email phone );
    That means the 0th element is 'name', and the 3rd element is 'phone'. In code terms:

    print "$records[0]\t$records[3]\n";

    produces name    phone. Does that help?

    If you find accessing data by name instead of by index is easier, you can assign to a hash:

    while (<DATA>) { chomp; my ($key, $value) = split; $value =~ tr/"//d; my %record; $record{$key} = $value; push @records, \%record; }
    You can then loop through records, printing just the elements you want:
    foreach my $rec (@records) { print "ID: $rec->{ID}\n"; print "Name: $rec->{name}\n"; }
    Is that more clear?
      the thing is i don't want to print ID, Name, etc. I want to print only the values. Gladys, Black, etc. i want to be able to control that. i want to be able to print it in a specific order.