הלינקייה: מגזין חודשי למפתחים

רוצה לשמוע על כל האירועים, המדריכים, הקורסים והמאמרים שנכתבו החודש ?
הלינקייה הינו מגזין חופשי בעברית שמשאיר אותך בעניינים.
בלי ספאם. בלי שטויות. פעם בחודש אצלך בתיבה.

Reference Exercise

  1. Implement a function that gets a hash ref, key and value - and inserts the new key/value into the hash
  2. Implement a function that takes a list ref and a value, and adds that value to the list
  3. Write a function called "filter" that takes a file name and a function reference and runs the function on every line in the file. Return a list of all the lines for which the function returned a true result
  4. The utility /sbin/ifconfig returns a list of all network interfaces in the system. Write a perl script to gather all the data into a data structure so we can write the following code:
    my @active = grep { $_->{rx} != 0 } @networks;
    print Dumper(\@active);
    
  5. Write a function called array_in_array that takes two arrays (by reference) and return the index of one array inside the other - if found, or undef if not found. here's a usage example:
    my @a = (1, 2, 3);
    my @b = (2, 3, 4, 1, 6, 1, 2, 3, 7);
    my $idx = array_in_array( \@a, \@b );
    # now $idx == 5
    
  6. Write a program that builds a properties database from property files. Each property file contains lines of the format key=value. The program takes a list of such files, and parses them to build a central dictionary, to allow random access to properties. Each property file looks like this (with different keys and values):
    name = Mike
    age = 57
    likes = blue
    

    Now, let's play with the data.

    • Write a function that takes file name and property, and fetches that property's value from the dictionary.
    • Write a function that takes a key and returns all the files that contain some value for this key.
  7. Write a program that takes as input a list of module names and their dependencies, and outputs the order in which the modules should be built. A module can only be built AFTER all of its dependencies.
    For example, given the following input:

    Luke: Han Solo, Leia, Yoda
    Leia: Padme Amidala, Anakin Skywalker
    Obi-Wan: Yoda
    Darth Vader: Anakin Skywalker
    

    The program should produce the output:

    Han Solo, Anakin Skywalker, Darth Vader, Yoda, Padme Amidala, Obi-Wan, Leia, Luke
    
  8. Write a function that removes the first element from each array passed to it. The return value of the function should be the number of elements removed from all arrays.
  9. Add error checking to the function written in exercise 5 so that the undef value is returned if one of the parameters is not an array.
  10. Implement a function called larger_than that takes a scalar and multiple list refs, and returns a list composed of all the input elements in the list refs that are larger than the given scalar
  11. Modify the previous function so that it takes a scalar, a code ref, and multiple list refs. The function should check all elements of every list against the scalar using the code ref. Return value is a list of all the elements which returned a true value with the given scalar
  12. Implement a function called make_counter which takes a number and returns a counter function for that number. The counter function should return an increasing number from 0 to the given parameter. Example usage:
      my $c = make_counter(5);
      my $d = make_counter(7);
    
      # prints 0 1 2
      print $c->(), $c->(), $c->(), "\n";
      # prints 0 1 2
      print $d->(), $d->(), $d->(), "\n";
      # prints 3 
      print $c->(), "\n";
    
    
  13. Implement a function called add_x that takes a number x and returns a function that adds x to its parameter. Example usage:

      my $add_2 = add_x(2);
      my $add_5 = add_x(5);
    
      # prints 12 15
      print $add_2->(10), $add_5->(10), "\n";
    
    
  14. Write a calculator in Perl/Tk. It should support: +, -, *, / as well as MR, MR, M+, M-
  15. Implement Tic-Tac-Toe game in Perl/Tk

Link To Solutions

course: