Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How do I insert a line into a file?

by Dominus (Parson)
on Mar 31, 2002 at 06:10 UTC ( #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
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? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2015-07-06 04:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls