Write a unix filter in perl (program that reads stdin and writes stdout) that will reformat a multi-record, comma delimited file with 4 fields per line and select only fields 1,3,4 and output the fields in the order 4,1,3. Assume that the file is massive and cannot be processed in memory.
for example: john@abc.com,Doe,John,M becomes M,john@abc.com,John
generate the data text file (text file created Windows Notepad is different from Unix file, e.g. carriage return.)
#!/usr/bin/perl open OUT, ">>in.txt" || die $!; my $i; $i=5; while ($i--){ print OUT "firstname$i@somedomain.com,lastname$i,firstname$i,mi$i\n"; } close OUT;
process the data
#!/usr/bin/perl open IN, "<in.txt" || die $!; #Perl will automatically store an error message in the special $! variable open OUT, ">out.txt" || die $!; while(<IN>){ chomp; @string = split(/,/); print OUT "$string[3],$string[0],$string[2]\n"; } close IN; close OUT;
What is the use of the keyword 'bless' in perl?
In order to delete a file on a unix filesystem: what permissions are required on the file itself? what permissions are required on the parent directory?
No permissions required on the file itself; write permission is required for the parent directory; execute permission is required for all parent directories back to the root.[3]
Given the database schema below, write an SQL query that returns a list of user email addresses with associated 'fname', where the
value of the interest field is 64.
+----------------------+ +--------------------------------+
|table: USER | | table: PROFILE |
|----------------------| +--------------------------------+
|email user_id perm | |user_id pref ic_ind |
+----------------------+ +--------------------------------+
+-----------------------------+
|table: DEMOGRAPHIC: |
|-----------------------------+
|user_id fname lname interest |
+-----------------------------+
SELECT U.email, D.fname FROM USER U LEFT JOIN DEMOGRAPHIC D ON D.user_id=U.user_id WHERE D.interest = '64'
How does one direct output on file descriptor 4 to stderr in shell?[4]
4>&2
How is memory attained and disposed of in C?[5]
attained - malloc
disposed of - free
How is the character '*' used to reference variables in C and Perl?
Perl: club
C: pointer
What operations (besides assignment) are performed below? What are the result values in the variables $x and $y?
8a. my $x = 0 | 2 | 4; 8b. my $y = 0 || 2 || 4;
8a. $x = 6 ("|" does the bitwise OR operation)
8b. $y = 2 (Binary “||” performs a short-circuit logical OR operation. That is, if the left operand is true, the right operand is not even evaluated. Scalar or list context propagates down to the right operand if it is evaluated. [2])
What is the result of each of the following expressions?
9a. my ($a,@b,$c) = qw( 1 2 3 4 5 ); 9b. my $a = (4,2,3,5,2);
9a. $a = 1, @b = [2, 3, 4, 5], $c=NULL
9b. $a = 2
Write a single regular expression to validate and capture the digits out of a phone number where area code is optional, and values ar separated by dashes, into 3 scalar variables.
matched: 123-345-5678, 345-5678
not matched: 1232-21-2222, 123.345.5678
^(([0-9]{3})-)?(\d{3})-(\d{4})$
NEED CODE?
Given a perl script that is being sent a file of newline delimited records on standard input, what is the result of the following statements?
local $/ = undef; my $var = <STDIN>;
Explain the difference between a signed integer and an unsigned integer
Signed integer includes 0,negative and postive values, and ranges from
to
. Unsigned integer does not have negative integer, and ranges from 0 to
.
In Perl, if $d contains the value 2 when you run the following code, what is printed out?
$c = $d == 2; print ++$c;**
$c = 2
In Perl, what variable stores the error caught by an eval block?[1]
$@
eval { ... }; if ($@) { errorHandler($@); }
In Perl, with what CPAN module can you grab a URL by using: "get 'http://www.yahoo.com'"
What is a downside of writing an insert query without explicitly specifying the columns to use? i.e. insert into mytable values (?, ?, ?)
What makes InnoDB different than MyISAM? How do you decide which to use?
What's a left join?
What's modperl and what are the advantages of using it?
What's the difference between a GET and a POST? What do you take into account when deciding which to use?





