Saturday, February 22, 2014

Bash: How to read file line by line

IFS=$'\n'

for line in $(cat file.txt)
do
       echo $line
done


OR

while read line
do
        echo $line
done < file

[While loop is the easiest method but it obliterates the formatting of lines including spaces and tabs.]


Thursday, February 20, 2014

Revert last submitted changelist from Perforce branch

Let's say Perforce trunk has changes c1,c2,c3. c3 is HOL. How do we revert the changes done through c3??


p4 sync @c2
p4 diff -se ...@c3 | p4 -x - edit
p4 sync @c3
p4 resolve -ay

Monday, January 6, 2014

How to enable warnings for Perl execution

1. Enable warnings from command line: perl -w

2. Through Shebang line: #!/usr/bin/perl -w

However this doesn't work in case of #!/usr/bin/env perl -w because env tries to treat "perl -w" as single argument.

3. use warnings - However this has lexical implications and only applies to current code

4. BEGIN{
$^W = 1
}

BEGIN block is executed during compilation and hence this sets warnings switch to true and applies to all the scripts that get executed/imported during this execution.