My mistake I credited the wrong code to you. I apologize. Here is the code as you originally posted for me.
# #!/usr/bin/perl -w # # use strict; # use Data::Dumper; # use diagnostics -verbose; # # use constant PART => 1; # use constant REV => 2; # # 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, # filename => './file.db' ); # # print ref $searchresult # ? "Located Part Number $part: @{$searchresult}[1 .. 7]\n" # : "Your Part Number ($part) Rev ($rev) could not be found...\n"; # # sub search { # my %args = @_; # my @return_record; # # local *PARTS_DB; # open PARTS_DB, $args{filename} or die "Cannot open file $args{fi +lename}: $!"; # while (my $record = <PARTS_DB>) { # chomp $record; # my @record = split /\|/, $record; # next unless $record[PART] eq $args{part} # and $record[REV] eq $args{rev}; # # @return_record = @record; # } # close PARTS_DB or die "Can't close PARTS_DB $args{filename}: $!" +; # return \ @return_record; # }
This is how it stands at this time with the changes. As you can see I do not use found at all in the new version.
#!/usr/bin/perl -w use strict; use Data::Dumper; use diagnostics -verbose; use constant PART => 0; use constant REV => 1; #This is where the user will enter the Part Number and Revision Level print "Enter the Part Number you wish to search for: "; my $part = <STDIN>; chomp $part; while (!$part){ # while $PartNumber is empty keep asking print "PartNumber? "; $part = <STDIN>; chomp($part); } print "Enter the Revision for ($part): "; my $rev = <STDIN>; chomp $rev; while (!$rev){ # while $rev is empty keep asking print "Revision? "; $rev = <STDIN>; chomp($rev); } my $searchresult = search( part => $part, rev => $rev, filename => './file.db', ); print ref $searchresult ? "Located Part Number: @{[join ':', @$searchresult ]}\n" # print th +e part number and the records : "Your Part Number ($part) Rev ($rev) could not be found....\n"; #p +rint if part number or rev is invalid # subroutine that takes the arguments from my $searchresult and checks # the text file for a matching part number and revision level sub search { my %args = @_; my $retval; local *PARTS_DB; open PARTS_DB, $args{filename} or die "Cannot open file $args{fil +ename}: $!"; while (my $record = <PARTS_DB>) { chomp $record; my @record = split /\|/, $record; next unless $record[PART] eq $args{part} and $record[REV] eq $args{rev}; close PARTS_DB or die "Can't close PARTS_DB $args{filename}: +$!"; return \ @record; } }
Kerry
"Yet what are all such gaieties to me
Whose thoughts are full of indices and surds?"
quotes the Lama

In reply to Re: Re^3: using join with a print ref statement by Bismark
in thread using join with a print ref statement by Bismark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.