BluePink BluePink
XHost
Gazduire site-uri web nelimitata ca spatiu si trafic lunar la doar 15 eur / an. Inregistrare domenii .ro .com .net .org .info .biz .com.ro .org.ro la preturi preferentiale. Pentru oferta detaliata accesati site-ul BluePink

Script-uri Perl


#! /usr/bin/perl
#Conversie din baza 10 in baza 2
use integer;

local($mand) = 255;
local($mor)  =   0;
foreach (@ARGV) {
    &Convert($_);
    $mand &= $_;
    $mor  |= $_;
}

printf("and\n");
&Convert($mand);
printf("or\n");
&Convert($mor);
# parametru : x numarul care trebuie convertit

sub Convert {

    local($x) = @_[0];
    die("Argument out of range : $x") if($x <0 || $x > 255);

    printf("%3d : ", $x);

    $m = 128;
    for ($i = 0; $i < 8 ; $i++) {
	if($m & $x) {
	    print 1;
	}
	else {
	    print 0;
	}
	$m = $m>>1;
    }
    printf("\n");

    1;
}

#!/usr/bin/perl
# cauta un fisier in toate subdirectoarele

if ($#ARGV != 0) {
    print "usage: findfile filename\n";
    exit;
}

$filename = $ARGV[0];

# cauta in directorul curent
$dir = `pwd`;
chop($dir);
&searchDirectory($dir);

sub searchDirectory {
    local($dir);
    local(@lines);
    local($line);
    local($file);
    local($subdir);

    $dir = $_[0];

    # verifica drepturile
    if(-x $dir) {

	# cauta in acest director
	@lines = `cd $dir; ls -l | grep $filename`;
	foreach $line (@lines) {
	    $line =~ /\s+(\S+)$/;
	    $file = $1;
	    print "Found $file in $dir\n";
	}

	# cauta orice subdirector
	@lines = `cd $dir; ls -l`;
	foreach $line (@lines) {
	    if($line =~ /^d/) {
		$line =~ /\s+(\S+)$/;
		$subdir = $dir."/".$1;
		&searchDirectory($subdir);
	    }
	}
    }
}

#!/usr/bin/perl
#Concersie fisiere dintr-un format in altul

if ($#ARGV != 5) {
    print "usage: fconvert intype outtype old new start stop\n";
    exit;
}

$intype = $ARGV[0];
$outtype = $ARGV[1];
$old = $ARGV[2];
$new = $ARGV[3];
$start = $ARGV[4];
$stop = $ARGV[5];

for ($i=$start; $i <= $stop; $i++) {

    $num = $i;
    if($i<10) {	$num = "00$i"; }
    elsif($i<100) { $num = "0$i"; }

    $cmd = "imgcvt -i $intype -o $outtype $old.$num $new.$num";
    print $cmd."\n";
    if(system($cmd)) { print "imgcvt failed\n"; }
}

#!/usr/bin/perl
#Cautare utilizator
#verifica ce utilizator este logat

if ($#ARGV != 0) {
    print "usage: finduser username\n";
    exit;
}

$username = $ARGV[0];
$machines = "insanity ".`systems sgi`;
chop($machines);
@machines = split(/ /,$machines);
@machines = sort(@machines);

foreach $machine (@machines) {

    if(`rusers $machine | grep $username`) {
	print "$username logged on $machine\n";
    }
}

#!/usr/bin/perl
#Modificare text 
# change all occurances of a string in a file to another string

if ($#ARGV != 3) {
    print "usage: chstring oldfile newfile oldstring newstring\n";
    exit;
}

$oldfile = $ARGV[0];
$newfile = $ARGV[1];
$old = $ARGV[2];
$new = $ARGV[3];

open(OF, $oldfile);
open(NF, ">$newfile");

# read in each line of the file
while ($line = <OF>) {
    $line =~ s/$old/$new/;
    print NF $line;
}

close(OF);
close(NF);