CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [kdejan] if else equality question: Edit Log


Feb 11, 2013, 8:53 PM

Views: 1052
Re: [kdejan] if else equality question

The operator '==' is for comparing numbers. Use the operator 'eq' to compare strings.

I have several other recommendations.

  • Always use strict and warnings.

  • Always use the three argument form of open.

  • Always use lexical (my) file handles.
  • Always explicitly close all open files.

  • Process each line of this file as a string. There is no reason to split it into a character array.

    Update: Added sample code (Untested due to lack of data)

    use strict; 
    use warnings;
    use Readonly;
    Readonly::Scalar my $GAP_PARTITION => 1417;
    Readonly::Scalar my $MAX_TITLE_SIZE => 1480;
    open( my $FILE, '<', "whatshappenin" ) or die $!;
    foreach my $line (<FILE>) {
    chomp $line;
    if ( length $line < $MAX_TITLE_SIZE ) { print $line ; next; }
    (my $temp = substr( $line, $GAP_PARTITION )) =~ tr /AaGg/0011/;
    substr($line, $GAP_PARTITION, length $temp, $temp);
    $line =~ s/(.)\s/$1/seg;
    print "$line\n";
    close $FILE;

    Good Luck,

    (This post was edited by BillKSmith on Feb 12, 2013, 7:48 AM)

  • Edit Log:
    Post edited by BillKSmith (Veteran) on Feb 12, 2013, 7:48 AM

    Search for (options) Powered by Gossamer Forum v.1.2.0

    Web Applications & Managed Hosting Powered by Gossamer Threads
    Visit our Mailing List Archives