in reply to To Separate alphanumeric

As mentioned above, this is not a homework outsourcing service. show us what you've tried and we will point you in the right direction if we can

You need to write a program that will carry out the following steps.

Have a look at the documentation linked above, try and code up the algorithm outlined and come back to us with specific Perl problems rather than a request to solve the entire problem.

Part of learning to code is learning a language and part of it is splitting up problems into sub-problems until each sub-problem can be written as a statement in the language you are using.

This is a discussion and education forum/community, mailing you a solution adds nothing to the community and offers an insufficient challenge to be worth doing for the satisfaction of solving by itself (perhaps try and get your end of term project written for you in under 160 chars and see if people will mail responses to you)

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^2: To Separate alphanumeric
by sowmya (Initiate) on Oct 08, 2010 at 07:53 UTC
    I just tried out using your guidelines.., it is as follow.. <CODE> #!/usr/bin/perl -w use warnings; use strict; open(FH,"<input") or die "cannot open"; open(FI,">alpha") or die "cannot open"; open(FL,">numeric") or die "cannot open"; $i=0; $a=0; while(<FH>) { @a=split //; for $a(@a) { print $b$i=$a; } if($b$i eq /A-Za-z/) { print FI $bi; } elsif($b$i eq /0-9/) { print FL $bi; } else { } } close FH; close FI; close FL; But it didn't work can you just look into whats the error
      Hi sowmya,

      You need to close your code tags, this should have looked mangled in the preview.
      You must have received errors when you tried to run this program, you should learn to read them ;) You could use diagnostics if the error messages seem cryptic
      I've modified your program to work and improved the coding style, however you need to work through errors to learn, so these are the changes required.

      General issues
      Use the three argument form of open, it prevents errors
      You should also include $! (check it out in perlvar) in your die message as it's good to know what went wrong
      Indirect filehandles are better practice and will allow you to pass them around your program when you're writing programs with sub-routines
      eg. open(my $input_file, '<', 'input') or die "cannot open input: $!";
      You must declare your variables when you use strict (see my)

      Logic issues
      What is the point of @b, you should process the elements of @a as you go
      You process the loop without doing anything and then examine only the first character of the array @b
      The way to make a regex test is =~ , eqis for string equality
      eg. if($a =~ /[A-Za-z]/) {
      You may want to print a place holder to mark the fact that a character was printed to the other file.
      To get the line of a file you are processing, take a look at $. in perlvar you could use this to generate a useful error message in your else block

      Try to make the changes above and next time close your code tags, look at the preview and copy in the errors you are seeing when describing your problem

      Happy learning, Utilitarian

      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."