Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Edit array in place (was: Help)

by Anonymous Monk
on Jun 10, 2002 at 04:15 UTC ( [id://173032]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

sub settings_smi_edit { $storeline = $q->param('id'); open(FILE, "info/smileset.txt"); @file = <FILE>; close(FILE); foreach $i (@file) { ($number, $image, $name, $text, $used) = split(/\|/, $i); if ($number eq $storeline) { @numb = ($number, $image, $name, $text, $used); } } }
Ok that I been trying this for a while, can't seem to get it. Ok after I get all taht in a while loop, say I edit @numb and I want to put it back into @file by the $storeline.

Get what Im saying
-Find it in @file
-Take that line
-Edit it
-Put it back in @file (updated)
-by i.d number

Also how would i *delete that certain array also

Thanks, Andrew

Edit kudra, 2002-06-10 Changed title

Replies are listed 'Best First'.
Re: Help
by Zaxo (Archbishop) on Jun 10, 2002 at 05:05 UTC

    You can find the line without splitting first:

    chomp @file; my @matches = grep { $file[$_] =~ /^\Q$storeline|\E/ } 0..$#file; no_match($storeline), return unless @matches; duped_ids($storeline), return if @matches > 1; my ($number, $image, $name, $text, $used) = split /\|/, $file[$matches +[0]]; # do what you do modifying those vars $file[$matches[0]] = join '|', $number, $image, $name, $text, $used; rename '/path/to/info/smileset.txt', '/path/to/info/smileset.bak' or d +ie $!; open FLE, '>', '/path/to/info/smileset.txt' or die $!; print FLE $_, $/ for @file; close FLE or die $!;
    The &no_match and &duped_ids subs are up to you, they would probably log the error.

    After Compline,
    Zaxo

Re: Help
by Anonymous Monk on Jun 10, 2002 at 05:22 UTC
    sub edit_set { if($q->param('text') eq '') { print "You need to enter in smile name <br><br> <a href=\"JavaScript:history.back(1)\">&lt;&lt;Back</a>"; } else { $storeline = $q->param('id'); open(FILE, "info/smileset.txt"); @file = <FILE>; close(FILE); chomp @file; my @matches = grep { $file[$_] =~ /^\Q$storeline|\E/ } 0..$#file; no_match($storeline), return unless @matches; duped_ids($storeline), return if @matches > 1; my ($number, $image, $name, $text, $used) = split /\|/, $file[$matches +[0]]; $number = $storeline; $image = $q->param('image'); $name = $q->param('text'); $text = $q->param('alt'); $used = $q->param('use'); $file[$matches[0]] = join '|', $number, $image, $name, $text, $used; rename 'info/smileset.txt', 'info/smileset.bak' or die $!; open FLE, '>', 'info/smileset.txt' or die $!; print FLE $_, $/ for @file; close FLE or die $!; }
    I get this error
    Missing right curly or square bracket at /var/securewww/virtual/webewe +bin.com/1/1/admin.cgi line 495, at end of line syntax error at /var/securewww/virtual/webewebin.com/1/1/admin.cgi lin +e 495, at EOF Execution of /var/securewww/virtual/webewebin.com/1/1/admin.cgi aborte +d due to compilation errors.
Re: Help
by Anonymous Monk on Jun 10, 2002 at 05:46 UTC
    Sorry bout that I just noticed I forgot a } I though it ment something in his code, until I saw end of the line, now does anyone know how to get rid of that certain array.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://173032]
Approved by virtualsue
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (8)
As of 2024-04-24 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found