See inline.
------------------------------------------------
On Fri, 17 Jan 2003 11:01:58 -0500, "Le Blanc, Kerry (Kerry)" <[EMAIL PROTECTED]>
wrote:
> I think I am getting close. With much help I have been able to tweek my original
>code down quite a bit. For the most part, everything is working as it should. What is
>stumping me right now is, how do I make sure that both the part number and the rev
>match before printing out the record. The part number is in $fields[0], the rev is in
>$fields[1]. The two fields are seperated by a pipe. I am attempting to send both
>inputs to the subroutine as arguments. thanks for any hints towards the right
>direction.
>
>
> #!/usr/bin/perl -w
>
> use strict;
> use Data::Dumper;
>
>
> print "Enter the Part Number you wish to search for: ";
> my $part = <STDIN>;
> chomp($part);
>
> print "Enter the Revison for ($part): ";
> my $rev = <STDIN>;
> chomp($rev);
>
> my $searchresult = &search(part => $part, rev => $rev);
>
>
> if (defined $searchresult) {
> print "Located Part Number $part: $$searchresult[1]\n";<-- How can I print all the
>fields without typing in each field
> }else { individually?
> print "Your Part Number ($part) could not be found...\n";
> }
>
> # This routine will accept a part number and rev as anonymous
> # hashes, and search thru a text file returning the entire
> # record (pipe delineated) of the 1st occurence
>
Actually it is just accepting a list, which it is automagically turning into a hash
(plain not anonymous) for you.
> sub search {
> my %args = @_;
> my $retval;
>
> local *FH;
> open (FH, './fai.txt') || die "Cannot open file: ($!)";
> my @parts = <FH>;
> my @rev = <FH>;
This stores two copies of the file in memory, do you need two copies?
> foreach my $line (@parts, @rev) {
This (I believe) is going to combine @parts and @rev so you will step through the file
twice. Are you expecting alternating lines in the file?
> my @fields = split(/\|/, $line);
> if ($args{part} eq $fields[0], $fields[1]) {
if (($args{'part'} eq $fields[0]) && ($args{'rev'} eq $fields[1])) {
> $retval = \@fields;
> last;
> }
> }
> close FH;
> return $retval;
> }
>
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]