Good afternoon. I'm learning perl, and confused by a simple code which prints :

Arch bits : OS Arch x86_64 : i686 OS Arch bits 1 : 64 OS Arch bits: 64 Now using for/if OS Arch x86_64 : i686 OS Arch bits 1 : 64

instead of :

Arch bits : OS Arch x86_64 : i686 OS Arch bits 3 : 32 OS Arch bits: 32 Now using for/if OS Arch x86_64 : i686 OS Arch bits 3 : 32

Code is as follow :

#!/usr/bin/perl print "Arch bits : $os_arch_bits\n"; #$os_arch = `uname -m`; #$os_arch =~ s/\n//g; #$os_arch =~ s/\r//g; $os_arch = 'i686'; if ($os_arch == 'x86_64') { print "OS Arch x86_64 : $os_arch\n"; $os_arch_bits = '64'; print "OS Arch bits 1 : $os_arch_bits\n"; } elsif ($os_arch == 'i386') { print "OS Arch i386 : $os_arch\n"; $os_arch_bits = '32'; print "OS Arch bits 2 : $os_arch_bits\n"; } elsif ($os_arch == 'i686') { print "OS Arch 64 : $os_arch\n"; $os_arch_bits = '32'; print "OS Arch bits 3 : $os_arch_bits\n"; } else { print "OS Arch 64 : $os_arch\n"; $os_arch_bits = 'XX'; print "OS Arch bits 4 : $os_arch_bits\n"; } print "OS Arch bits: $os_arch_bits\n"; print "Now using for/if\n"; for ($os_arch) { if ("x86_64") { print "OS Arch x86_64 : $os_arch\n"; $os_arch_bits = '64'; print "OS Arch bits 1 : $os_arch_bits\n"; } elsif ("i386") { print "OS Arch i386 : $os_arch\n"; $os_arch_bits = '32'; print "OS Arch bits 2 : $os_arch_bits\n"; } elsif ("i686") { print "OS Arch 64 : $os_arch\n"; $os_arch_bits = '32'; print "OS Arch bits 3 : $os_arch_bits\n"; } else { print "OS Arch 64 : $os_arch\n"; $os_arch_bits = 'XX'; print "OS Arch bits 4 : $os_arch_bits\n"; } }
Help will be appreciated :)

In reply to simple "if.. elsif.. else.." statements, trying "for.. if.." too by JBzh

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.