First two things to fix:

  1. Your open statement is broken. Count the quotation marks -- I think you'll see this is not a casual problem. See if you can fix that up a bit.
  2. Your use of flock is, I suspect, incorrect, which is understandable given your newness to the language. I recommend commenting that line out until the basic logic is working. Then move into more advanced features like file locking.

I've taken the liberty of reformatting your code so it is more readable, and adding the requisite use strict; and use warnings; statements. Please use them. They can be painful at first, but it's a good pain -- they teach you exactly what you are doing wrong as you learn the language. Together they comprise the single best debugging tool Perl has, and all you have to do is not be stubborn and they will reward you in droves.

#!/usr/bin/perl use strict; use warnings; if ($surv ne "") { $survmatch = "n"; open (survdat, "+< /xxx ||cmn::dienice("$lang::open_file_write"); flock (survdat,2); @raw_data=<survdat>; foreach $survinn (@raw_data) { chomp ($survinn); ($survwk,$survn,$survtm)=split(/,/,$survinn); if ((uc($survn) eq uc($poolm)) && ($survwk = $weekin)) { s/$survtm/$surv/i; $survmatch="y"; seek(survdat,0,0); print survdat @raw_data; } } if ($survmatch eq "n") { print survdat "$weekin,$poolm,$surv\r\n"; } } close survdat; exit; __END__ S:\Steve\Dev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail>update1a.pl Unquoted string "survdat" may clash with future reserved word at S:\St +eve\Dev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl lin +e 9. Scalar found where operator expected at S:\Steve\Dev\PerlMonks\P-2014- +04-02@1439-Array-Update-Fail\update1a.pl line 9, near ""+< /xxx ||cmn +: :dienice("$lang::open_file_write" (Missing operator before $lang::open_file_write?) String found where operator expected at S:\Steve\Dev\PerlMonks\P-2014- +04-02@1439-Array-Update-Fail\update1a.pl line 19, near "$survmatch="" (Might be a runaway multi-line "" string starting on line 9) (Missing semicolon on previous line?) Possible unintended interpolation of @raw_data in string at S:\Steve\D +ev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Possible unintended interpolation of @raw_data in string at S:\Steve\D +ev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Unquoted string "survdat" may clash with future reserved word at S:\St +eve\Dev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl lin +e 26. Global symbol "$surv" requires explicit package name at S:\Steve\Dev\P +erlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 6. Global symbol "$survmatch" requires explicit package name at S:\Steve\ +Dev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 8. syntax error at S:\Steve\Dev\PerlMonks\P-2014-04-02@1439-Array-Update- +Fail\update1a.pl line 9, near ""+< /xxx ||cmn::dienice("$lang::open_f +i le_write" Global symbol "@raw_data" requires explicit package name at S:\Steve\D +ev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survinn" requires explicit package name at S:\Steve\De +v\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "@raw_data" requires explicit package name at S:\Steve\D +ev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survinn" requires explicit package name at S:\Steve\De +v\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survwk" requires explicit package name at S:\Steve\Dev +\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survn" requires explicit package name at S:\Steve\Dev\ +PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survtm" requires explicit package name at S:\Steve\Dev +\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survinn" requires explicit package name at S:\Steve\De +v\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survn" requires explicit package name at S:\Steve\Dev\ +PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$poolm" requires explicit package name at S:\Steve\Dev\ +PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survwk" requires explicit package name at S:\Steve\Dev +\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$weekin" requires explicit package name at S:\Steve\Dev +\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survtm" requires explicit package name at S:\Steve\Dev +\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$surv" requires explicit package name at S:\Steve\Dev\P +erlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$survmatch" requires explicit package name at S:\Steve\ +Dev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 9. Global symbol "$weekin" requires explicit package name at S:\Steve\Dev +\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 26. Global symbol "$poolm" requires explicit package name at S:\Steve\Dev\ +PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 26. Global symbol "$surv" requires explicit package name at S:\Steve\Dev\P +erlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl line 26. syntax error at S:\Steve\Dev\PerlMonks\P-2014-04-02@1439-Array-Update- +Fail\update1a.pl line 28, near "}" S:\Steve\Dev\PerlMonks\P-2014-04-02@1439-Array-Update-Fail\update1a.pl + has too many errors.


In reply to Re: replace a value in an array by marinersk
in thread replace a value in an array by firsttime

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.