Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

How do I insert a line into a file?

by Dominus (Parson)
on Mar 31, 2002 at 06:10 UTC ( [id://155567]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
            perl -i.bak -lpe 's/PERL/perl/g' file
    
  2. or download this
            {
              local ($^I, @ARGV) = ('.bak', 'file');
    ...
                print;
              }
            }
    
  3. or download this
            tie @lines, 'Tie::File', 'file' or die ...;
            for (@lines) {
              s/PERL/perl/g;
            }
            untie @lines;
    
  4. or download this
            for (@lines) {
              if (/<!-- insert here -->/) {
    ...
                last;
              }
            }
    
  5. or download this
            unshift @lines, $new;   # Or add more than one record
    
  6. or download this
            open DB, "< $database" or die ...;
    
    ...
              my $user = shift;
              return $db{$username};
            }
    
  7. or download this
            tie @DB, 'Tie::File', $database or die ...;
            for (@DB) {
    ...
              my $username = shift;
              return $DB[$recno{$username}];
            }
    
  8. or download this
            sub replace_data {
              my ($username, $new_data) = @_;
    ...
              $data[1] = $crypted_password;
              replace_data($username, join(':', @data));
            }
    

Log In?
Username:
Password:

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

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

    No recent polls found