Hi, i have now been struggling with the same bit of code for weeks and would really appreciate some help. I am trying to sort a file into catergories and then have a menu where the user can select the catergory they want to look at then return to the main menu for anothe choice etc. In principal this sounds easy! I posted a question a few week ago and was advised to write a sub-routine to help. I have been trying but can't get anywhere. Could anyone look at my code to suggest anything??? Since i have written the sub-routine - none of the results are displayed when the user selects an option. thankx.
#! /usr/local/bin/perl -w use strict; my $num_of_params; $num_of_params = @ARGV; if ($num_of_params < 2) { die ("\n You haven't entered enough parameters \n\n"); } + open (FH, $ARGV[0]) or die "unable to open file"; open (OUTFILE, ">$ARGV[1]"); my $line; my @array; my $first=0; my $second=0; my $third; my $forth; my $choice; my $others; while (<FH>) { chomp; my @array = split /\s+/; $array[8] =~ tr/%//d; } print STDOUT "\nPlease select the catergory of results that you wish t +o see;\n\n \t1. first \n\t2. second \n\t3. third \n\t4. forth \n\t5. Others etc\ +n\t6. Exit program\n\n"; my $choice = <STDIN>; chomp $choice; print "\n Identifier \t\t%identity \n\n"; catergory ($first); if ($choice eq 1) { print $first; } sub catergory { my @array = @_; if (($array[1] =~ m{/:first\|\w+\|\w+}) && ($array[8] > 95)) { my $first = "$array[1]\t$array[8]\n"; } elsif (($array[1] =~ m{/:second\|\w+\|\w+}) && ($array[8] > 95)) { $second = "$array[1]\t$array[8]\n"; } elsif (($array[1] =~ m{/:third\|\w+\|\w+}) && ($array[8] < 95)) { $third = "$array[1]\t$array[8]\n"; } elsif (($array[1] =~ m{/:forth\|\w+\|\w+}) && ($array[8] < 95)) { $forth = "$array[1]\t$array[8]\n"; } elsif (($choice eq 5) && ($array[1] =~ m{/:other\|\w+\|\w+}) { $others = "$array[1]\t\t$array[8]\n"; } return $first; return $second; return $third; return $forth; return $others; } close OUTFILE;

In reply to struggling with sub-routines by Anonymous Monk

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.