Perl script to add Header to files

The following script will add text to the beginning of files.

Donwload here. perlheader.pdf

This is done in three steps

1) This script copies the contents of a file to local variable by slurping.

2) The necessary text that needs to be added at the beginning of the file is added.

3) Then the original contents of the file are added using the local variable.




# Filename:

# Author : A.G.Raja

# Website :

# License : GPL

# pass files as arguments to this script

# this script will add the header text

use strict;

use warnings;

sub addheader{


my $text = do { local( @ARGV, $/ ) = $infile ; <> } ;


print FILE $header;

print FILE $text;

close FILE


my $argnum;

foreach $argnum (0 .. $#ARGV){

my $infile = $ARGV[$argnum];

# Edit line below to change header text

my $header = “Header line 1nHeader line 2nHeader line 3n”;



# chmod +x

# ./ *.txt


Donwload here. perlheader.pdf


16 thoughts on “Perl script to add Header to files

  1. The script is quite useful, although it has got a minor bug into it.
    The line below
    my $text = do { local( @ARGV, $/ ) = $infile ; } ;
    should be changed to
    my @text = do { local( @ARGV, $/ ) = $infile ; } ;

    Please use @text instead of $text

  2. Any port in a storm
    clenbuterol [url=]clenbuterol[/url] tussionex [url=]tussionex[/url] protopic [url=]protopic[/url] ciprobay [url=]ciprobay[/url] temazepam [url=]temazepam[/url] targretin [url=]targretin[/url] hoodia [url=]hoodia[/url]

  3. Запчасти к зарубежной ДСТ. ЗАО «Торговый дом «Руслэнд-Инвест» предлагает широкий ассортимент запасных частей и расходных материалов для техники и оборудования от основных мировых производителей: CATERPILLAR, KOMATSU, HITACHI, KATO, CASE, DEUTZ…

  4. В развитии всех этих заболеваний прослеживается четкая этапность. Задолго до того, как вы услышите в медицинском кабинете диагноз: «Аденоиды», – вы заметите, что ваш ребенок дышит через открытый рот, а нос у него постоянно забит.
    Покажет ли тест на беременность беременность 3 недели.

  5. Кстати, неплохо описал этот момент, а то я раньше смотрел только в новостях описания, а там они такие расплывчитые.

  6. Hi AG Raja,

    Im trying to use this script in one of my scripts, when I run it in its own script it works without problems, but when i use it in my big script on the line :

    my $text = do { local( @ARGV, $/ ) = $infile ; } ;

    my script hangs, I have worked out that this is because im using an ARGV as an input to my actual script large script. I dont really understand how this lines work, but is there a way to change it to not use @ARGV?

    it would be great if you could help, but i realise this posting is very old.

    many thanks,


  7. Is definitely the water tank easily accessible and not cramped for pouring water at?

    Is the pot by very easy to slip at and also away the unit?
    Will the coffee basket eliminate easily? are really the components which really want just casual wash very easy to go?
    . all these coffee makers, though they might be less acquainted, offer one thing different for coffee enthusiasts, regardless through the
    sheer variety of coffee styles and additionally flavors available for pod gadgets, and/or previous planet
    flavor created.

  8. If generally there is certainly one piece of clothing that
    could completely ruin your very own whole the summer months it is actually definitely a swimsuit.
    Keep your very own bikini bottom dark and try graphics,
    color blocking or vertical stripes, on the top and
    this will most likely draw the eye upward. Explore our swimwear for women internet based today.
    .These are typically also easily available online from specialty stores or the online equivalent of
    the true world retailers you cannot feel bothered in
    order to get your very own lazy backside away in order to.Featuring frills, kooky hearts
    and glamorous cut away matches, Accessorize produces costumes for every taste and shape.

  9. PAINT/WALL DECOR: When your are limited on whether you could
    paint, generally there are numerous other stuff you may do in order to change the appearance of your very own eating room to help make it warm, inviting and also
    welcome for your children and also guests also. however there is some fraction as part of house where whole family congregate like TV lounge and dining room so that they must try to be ornamented in really
    separated which each person likes the environment.
    some individuals additionally like granite top dining table because they feel
    it is tradition.Most modern dining tables seem like a powerful artwork, having
    countless themes, types and sizes.

  10. A eating table can feel described with numerous statement:
    functional, decorative, useful, gorgeous, etc. It is a very good furniture
    stuff for a little gathering, like friends seated around facing each other,
    chilling, playing cards, having snacks or perhaps indulging as
    part of some other activities. And some other prospect is to walk
    off as part of superstore within the oval glass dining
    table of home and also select through as part of the constrained bits and also pieces.
    Because generally there are so many different modern
    dining table sets, you will definitely have many different alternatives in the kind of table that you get.

  11. These are extrêmement technique form courant des lunettes avec ULTRAVIOLET et aussi le verre antireflet à garantit maximum le confort pour les coureurs qui exige homogénéité et aussi le confort extrême.
    Below ULTRAVIOLET la protection et/ou current content qui sera le succès
    ou dans le meilleur la configuration, LA lunettes d’Interdiction de Ray bon marché qui il fera plus probable rencontre. do pas va de le style, outre leur build fl données par le créateur de chaque un des solaire toutefois fait pas get une prise de le exact même achievements.

  12. Delhi wedding day photography is actually often a strategy
    and artifacts associated to savings on unforgettable moments embraced times during the
    ceremony. Your very own camera will most likely automatically adjust to the light.
    Digital cameras enable photographers to assess the illumination and also composition of their work immediately upon taking
    the photograph.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s